Since getenv() method is no more deprecated in Java SE 5.0, we can start using this to get the System Environment variables. This method has two forms:

  • getenv() -> returns the Map contains the System Environment. NULL is returned if there are no System Environment varibales.

    Ex: Map sysEnvMap = System.getenv();

  • String getenv(String key) -> returns the value of passed environment key. NULL is returned if the key does not exist.

    Ex: String sysEnvStr = System.getenv("JAVA_HOME");

Author: Srinivas Ivaturi