Gets the value of the specified environment variable. An environment variable is a system-dependent external named value.
If a security manager exists, its
checkPermission
method is called with a
permission. This may result in a RuntimePermission
("getenv."+name)SecurityException
being thrown. If no exception is thrown the value of the
variable name
is returned.
System
properties and environment variables are both
conceptually mappings between names and values. Both
mechanisms can be used to pass user-defined information to a
Java process. Environment variables have a more global effect,
because they are visible to all descendants of the process
which defines them, not just the immediate Java subprocess.
They can have subtly different semantics, such as case
insensitivity, on different operating systems. For these
reasons, environment variables are more likely to have
unintended side effects. It is best to use system properties
where possible. Environment variables should be used when a
global effect is desired, or when an external system interface
requires an environment variable (such as PATH
).
On UNIX systems the alphabetic case of name
is
typically significant, while on Microsoft Windows systems it is
typically not. For example, the expression
System.getenv("FOO").equals(System.getenv("foo"))
is likely to be true on Microsoft Windows.
name | the name of the environment variable |
null
if the variable is not defined in the system environment
NullPointerException | if name is null | |
SecurityException
| if a security manager exists and its
checkPermission
method doesn't allow access to the environment variable
name |
getenv(), ProcessBuilder.environment()
Diagram: System