Getting all properties from system in Java

In this section you create console application displays all properties from your OS.

Begin with create MyProperties project. Choose from menu in Netbeans File->New Project.

In New Project window select from Categories section Java and from Projects section Java Application. Click the Next button.

In Project Name field write MyProperties and in Create Main Class change package to dora.

Click the Finish button.

Open MyProperties.java file in Project window.

Paste into it this code:

package dora;
import java.util.Enumeration;
import java.util.Properties;
public class MyProperties {
    public static void main(String[] args) {
        Properties props = System.getProperties();
        Enumeration en = props.propertyNames();
        while(en.hasMoreElements())
        {
            String key = (String)en.nextElement();
            String value = props.getProperty(key);
            System.out.println(key+" = "+value);
        }
                                           }
}

System class has getProperties method which get Properties object. For this object you may call propertyNames method. This method return Enumeration interface. Looping for this map you get keys from properties. Calling getProperty with every key of Properties object  you give value. Enumeration interface has hasMoreElements method which search if is else any element in this map. If yes, you get it calling nextElement method.

Run your application. You see all properties: key and its value. It is part of result this application: