Pin It

How to get information about the Environment Variables used through a Java program ?.

Program to demonstrate how to get information about the Environment Variables used through a Java 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 : 

 
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot