Monday, October 7, 2013

Get system properties with System.getProperties()

The getProperties() method of java.lang.System class return a Properties object. With this Properties object, we can get all the keys in this property list by calling its propertyNames() method. Then gets the system property indicated by the specified key by calling its System.getProperty(String key)/or getProperty(String key) method of the Properties object.

Get system properties with System.getProperties()
Get system properties with System.getProperties()

package java_systemproperties;

import java.util.Enumeration;
import java.util.Properties;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class Java_SystemProperties {

    public static void main(String[] args) {
        Properties properties = System.getProperties();
        System.out.println(properties.toString());
        System.out.println("\n");
        
        Enumeration<String> prop = 
                (Enumeration<String>) properties.propertyNames();
        
        while(prop.hasMoreElements()){
            String propName = prop.nextElement();
            System.out.println(
                    propName + " : " +
                    System.getProperty(propName));
        }
    }
}


Related: Get info of running jvm, os and cpu - tested on Windows 10

1 comment: