How to get the value of System Property and Environment Variable in Java? Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report How to get the value of Environment variables? The System class in Java provides a method named System.getenv() which can be used to get the value of an environment variable set in the current system. Syntax: public static String getenv(String key); where key is the Environment variable whose values we want Below example illustrates how to use System.getenv() to get the System environment variable: Example 1: To get the value of a specific environment variable java // Java program to get the value // of a specific environment variable // using System.getenv() method public class GFG { public static void main(String[] args) { // Get the value of // the TEMP environment variable System.out.println(System.getenv("TEMP")); // Get the value of // the OS environment variable System.out.println(System.getenv("OS")); // Get the value of // the JAVA_HOME environment variable System.out.println(System.getenv("JAVA_HOME")); } } Output: Example 2: To get the value of all environment variables at once java // Java program to get the value // of all environment variables at once // using System.getenv() method import java.util.Map; public class GFG { public static void main(String[] args) { // Get the value of // all environment variables at once // and store it in Map Map<String, String> env = System.getenv(); for (String envName : env.keySet()) { System.out.format("%s=%s%n", envName, env.get(envName)); } } } Output: Note: The output will depend on the system on which you run the above code. A sample output is given above How to get the value of System Property? The System class in Java has two methods used to read system properties: java.lang.System.getProperty(String key): fetches only those properties – values that you will specify using the key(associated to that particular value that you want). Example: Java // Java Program illustrating the working // of getProperty(String key) method import java.lang.*; import java.util.Properties; public class NewClass { public static void main(String[] args) { // Printing Name of the system property System.out.println("user.dir: " + System.getProperty( "user.dir")); // Fetches the property set with 'home' key System.out.println("home: " + System.getProperty( "home")); // Resulting in Null as no property is present // Printing 'name of Operating System' System.out.println("os.name: " + System.getProperty( "os.name")); // Printing 'JAVA Runtime version' System.out.println("version: " + System.getProperty( "java.runtime.version")); // Printing 'name' property System.out.println("name: " + System.getProperty( "name")); // Resulting in Null as no property is present } } Output: user.dir: /tmp/hsperfdata_bot home: null os.name: Linux version: 1.8.0_101-b13 name: null java.lang.System.getProperty(String key, String definition): helps you to create your own key-value sets that you want. Example: Java // Java Program illustrating the working of // getProperty(String key, String definition) method import java.lang.*; import java.util.Properties; public class NewClass { public static void main(String[] args) { // Here key = "Hello" and // System Property = "Geeks" System.out.println("Hello property : " + System.getProperty( "Hello", "Geeks")); // Here key = "Geek" and // System Property = "For Geeks" System.out.println("System-property :" + System.getProperty( "System", "For Geeks")); // Here key = "Property" and // System Property = null System.out.println("Property-property :" + System.getProperty( "Property")); } } Output: Hello key property : Geeks System key property :For Geeks Property key property :null java.lang.System.getProperties(): fetches all the properties – values that the JVM on your System gets from the Operating System. Example: Java // Java Program illustrating the working of // getProperties() method public class GFG { public static void main(String[] args) { System.out.println(System.getProperties()) } } Output: Comment More infoAdvertise with us Next Article Java Program to Get System Name for Windows and Linux Machine R Rajnis09 Follow Improve Article Tags : Java Java Programs java-basics Practice Tags : Java Similar Reads Java Program to Determine the Name and Version of the Operating System The inbuilt System class in Java provides getProperty() method which is used to obtain the properties of the current working operating system. The System class has two versions of getProperty(). Both retrieve the value of the property named in the argument list. Methods: getProperty() version 1getPr 2 min read Setting Up Proxy Connection to a System in Java In today's networking environments, categorically corporate ones, application developers have to deal with proxies virtually as often as system administrators. In some cases the application should utilize the system default settings, in other cases, it will be additive to have very tight control ove 7 min read How to Find the Number of Arguments Provided at Runtime in Java? The Java command-line argument is an argument that is passed at the time of running of a program. i.e. in order to make a program dynamic, there may be cases where we pass the arguments at runtime. Usually, via command-line arguments, they get passed and there are ways to find the number of argument 3 min read Java Program to Get System IP Address in Windows and Linux Machine IP Address: An Internet Protocol address is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. Packages used: io (input-output): This package provides for system input and output through data streams, serialization, and the fi 2 min read Java Program to Get System Name for Windows and Linux Machine We can get the System name for a Windows or Linux machine using the getHostName() method of the InetAddress class of java.net package after getting the IP address of the system using getLocalHost() method of the same class. The class InetAddress gets the IP address of any hostname. Â getLocalHost() m 1 min read How to Access Private Field and Method Using Reflection in Java? If we want to access Private Field and method using Reflection we just need to call setAccessible(true) on the field or method object which you want to access. Class.getDeclaredField(String fieldName) or Class.getDeclaredFields() can be used to get private fields. Whereas Class.getDeclaredMethod(Str 3 min read Like