Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What system properties are set by OpenJDK's vm that differentiate it from Sun/Oracle's vm?

Tags:

java

openjdk

Question: What system properties are set by OpenJDK's vm so that I can identify that I am running under OpenJDK and not under Sun/Oracle's vm?

As shown here: https://gist.github.com/sinewalker/3890869, the following system properties are NOT sufficient for differentiating between OpenJDK's VM and Sun/Oracle's VM:

System properties:

System.out.println(System.getProperty("java.vendor"));
System.out.println(System.getProperty("java.vendor.url"));
System.out.println(System.getProperty("java.version"));

Outputs the following using OpenJDK's vm (these are the same values you would see on Sun's VM):

Sun Microsystems Inc.
http://java.sun.com/
1.6.0_24

I was expecting the property values to reflect what is output by the java command:

$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.4) (6b24-1.11.4-1ubuntu0.12.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
like image 374
Chris Snow Avatar asked Aug 04 '13 19:08

Chris Snow


People also ask

What is difference between OpenJDK and Oracle JDK?

The biggest difference between OpenJDK and Oracle JDK is licensing. OpenJDK is completely open source Java with a GNU General Public License. Oracle JDK requires a commercial license under Oracle Binary Code License Agreement. But there are many other differences within support and cost, too.

How do I set system properties in environment variables?

To get a specific system property you can use System. getProperty(String key) or System. getProperty(String key, String def) . Environment variables are set in the OS, e.g. in Linux export HOME=/Users/myusername or on Windows SET WINDIR=C:\Windows etc, and, unlike properties, may not be set at runtime.

What are system properties?

System Properties is a section of Microsoft Windows for editing operating system settings, including hardware settings, connectivity, user profiles, security settings, and the computer name.


1 Answers

Try using these:

System.out.println(System.getProperty("java.vm.version"));
System.out.println(System.getProperty("java.runtime.name"));
System.out.println(System.getProperty("java.vm.name"));

You might also like System#getProperties():

System.getProperties().list(System.out);

which will list all the current System properties, to System.out.

like image 81
Rohit Jain Avatar answered Sep 18 '22 04:09

Rohit Jain