Java System Class

System class cannot be instantiated. Here are some example how to retrieve the system property using keys:

public class PropertiesExample {

    public static void main(String[] args) {

        System.out.println("Version of java : " + System.getProperty("java.version"));
        System.out.println("Vendor : " + System.getProperty("java.vendor"));
        System.out.println("User Name : " + System.getProperty("user.name"));
        
    }
}

Debraj Malllick output

output


To retrieve all the keys use the following code:

Enumeration<String> prop = (Enumeration<String>) System.getProperties().propertyNames();
while(prop.hasMoreElements()){
            //To get all the keys
            System.out.println("Key = "+prop.nextElement().toString());
}

To get all the values of the keys, use the above code with a small change:

Enumeration<String> prop = (Enumeration<String>) System.getProperties().propertyNames();
while(prop.hasMoreElements()){
   System.out.println("Value = "+System.getProperty(prop.nextElement().toString()));
}

Now if you like to know how many processors your machine have, copy and paste the following code:

System.out.println("Number of Available processors = " + Runtime.getRuntime().availableProcessors());
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: