System properties are key/value pairs that are external to your Java application. The Java System object provides a mechanism for reading the names and values of these external system properties into your Java application. The preceding phrase shows how you can set and get a system property using the Java System object. You can also retrieve all the system properties into a properties object using the following statement: Properties systemProps = System.getProperties(); There is also a method for retrieving just the system property names. The following code snippet shows how you can retrieve all the system property names and then retrieve each property using its name: Properties props = System.getProperties(); Enumeration propertyNames = props.propertyNames(); String key = ""; while (propertyNames.hasMoreElements()) { key = (String) propertyNames.nextElement(); System.out.println(key + "=" + props.getProperty(key)); } |