Environment Variables - I

29 May 2008

Environment variables are used by operating systems to pass useful information (configurations) to the applications. Environment variables are key/value pairs very much like properties. The key and the value, both are strings. To set environment variables, please read system documentation as it varies from one operating system to another.

In our Java applications, we use System.getEnv to retrieve environment variable values. If no argument is passed, getEnv will return an instance of java.util.Map which will be read only. In the returned map, the keys are the environment variable names, and the map values are the environment variable values.

Review the example below:

import java.util.Map;
 
public class EnvironmentMapEx{
    public static void main (String[] args) {
        Map<String, String> environment = System.getenv();
        for (String environmentName: environment .keySet()) {
            System.out.format("%s=%s%n", environmentName, environment.get(environmentName));
        }
    }
}

del.icio.us:Environment Variables - I  digg:Environment Variables - I  spurl:Environment Variables - I  wists:Environment Variables - I  simpy:Environment Variables - I  newsvine:Environment Variables - I  blinklist:Environment Variables - I  furl:Environment Variables - I  reddit:Environment Variables - I  fark:Environment Variables - I  blogmarks:Environment Variables - I  Y!:Environment Variables - I  smarking:Environment Variables - I  magnolia:Environment Variables - I  segnalo:Environment Variables - I  gifttagging:Environment Variables - I

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Environment Variables - I

Leave a Reply