Get the version of Java runtime

There may be occasions when you will need to do different processing for different servers based on the java versions present. You can simple use the System.getProperty(“java.version”) to get the current java version of the runtime.

public class Test {
public static void main(String[] args){
System.out.println(System.getProperty(“java.version”));
}
}

If you want to get the major minor version of Java you can use :

System.out.println(System.getProperty(“java.class.version”));

Similarly there are a set of system properties which can come handy at many times. To get a complete list of all the java properties, run the following program ::

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

public class Test {

public static void main(String[] args){
Properties p = System.getProperties();
Enumeration e = p.propertyNames();
while(e.hasMoreElements()){
String pro = (String) e.nextElement();
System.out.println(pro + ” :: ” + System.getProperty(pro));
}
}
}

Happy Coding 🙂

Advertisements

Tags: , , , , ,

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: