
- Java.lang Package classes
- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package extras
- Java.lang - Interfaces
- Java.lang - Errors
- Java.lang - Exceptions
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
Java.lang.System.getenv() Method
Description
The java.lang.System.getenv(String name) method gets the value of the specified environment variable. An environment variable is a system-dependent external named value.
Environment variables should be used when a global effect is desired, or when an external system interface requires an environment variable (such as PATH).
Declaration
Following is the declaration for java.lang.System.getenv() method
public static String getenv(String name)
Parameters
name − This is the name of the environment variable.
Return Value
This method returns the string value of the variable, or null if the variable is not defined in the system environment.
Exception
NullPointerException − if name is null.
SecurityException − if a security manager exists and its checkPermission method doesn't allow access to the process environment.
Example
The following example shows the usage of java.lang.System.getenv() method.
package com.tutorialspoint; import java.lang.*; public class SystemDemo { public static void main(String[] args) throws Exception { // gets the value of the specified environment variable "PATH" System.out.println("System.getenv("PATH") = "); System.out.println(System.getenv("PATH")); // gets the value of the specified environment variable "TEMP" System.out.print("System.getenv("TEMP") = "); System.out.println(System.getenv("TEMP")); // gets the value of the specified environment variable "USERNAME" System.out.print("System.getenv("USERNAME") = "); System.out.println(System.getenv("USERNAME")); } }
Let us compile and run the above program, this will produce the following result −
System.getenv("PATH") = C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem System.getenv("TEMP") = C:\DOCUME~1\AMIT~1.AMI\LOCALS~1\Temp System.getenv("USERNAME") = amroodAdmin