Wednesday, February 25, 2009

Listing all Environment Variables and System Properties of a Java Application

When a Java Application initiates, by default it is loaded with some environment variables and system properties it can use. Using these environment variables and system properties ensures 100% platform independence. Following is a program which lists all the environment variables and system properties a Java Application can use.

EnvironmentVariables.java

import java.util.*;

/**

 * @author Shazin Sadakath

 * 

**/

public class EnvironmentVariables{

              public static void main(String[] args){

                         Map env = System.getenv();

                         Collection col = env.keySet();

                         System.out.println(”– Environment Variables –\n”);

                         for(String s:col){

                                   System.out.println(s + “=” + env.get(s));

                         }

                         System.out.println();

                         Properties props = System.getProperties();

                         props.list(System.out);

            }

}

No comments:

Post a Comment