Program to demonstrate how to get information about the Environment Variables used through a Java program.
Output of the program :
package com.hubberspot.environmentVariables;
import java.util.Map;
import java.util.Set;
public class EnvironmentVariablesDemo {
public static void main(String[] args) {
// In order to get information about the environment variables
// used we call java.lang.System class's getenv() method
// It retirns back a map storing environment variable name and
// value
Map < String, String > environmentVariableMap = System.getenv();
// We get all the names of environment variables as a set
// using keySet() method of map of environment variables
Set < String > keySet = environmentVariableMap.keySet();
// We loop each and every element of the map
// and print the name and value of the environment variables
for(String environmentKey : keySet){
String environmentValue = environmentVariableMap.get(environmentKey);
System.out.println(environmentKey + " = " + environmentValue);
}
}
}
Output of the program :
