26

Using java -version gives me this.

java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

Is it an OpenJDK or OracleJDK ?

Abhishek Singh
  • 10,243
  • 22
  • 74
  • 108
  • 3
    The second line mentiones "HotSpot" which is the internal name of the Oracle VM. Hence it seems to be the OracleJDK. – Robert Nov 24 '15 at 13:41
  • first thing to ask yourself: which one did you install on your machine? – Stultuske Nov 24 '15 at 13:44
  • I have installed on machine. It was there already. It is Oracle JDK. See answer. – Abhishek Singh Nov 24 '15 at 13:45
  • What if I install both of them?! This will be probably default use case: I install both, develop on Oracle and make release with OpenJDK... now how to know with which one I am building? ¯\\_(ツ)_/¯ – Ewoks Feb 08 '19 at 21:59

4 Answers4

17

I think that you're using OracleJDK.

As I saw with a google search, the openJDK --version output is like this:

java -version

openjdk version "1.8.0-internal"

OpenJDK Runtime Environment (build 1.8.0-internal-0)

OpenJDK 64-Bit Zero VM (build 25.0-b20-internal, interpreted mode)

See: http://mail.openjdk.java.net/pipermail/jdk8-dev/2013-July/002840.html

JFPicard
  • 5,029
  • 3
  • 19
  • 43
10

On debian, jessie-backports, openjdk-8:

openjdk version "1.8.0_66-internal"
OpenJDK Runtime Environment (build 1.8.0_66-internal-b17)
OpenJDK 64-Bit Server VM (build 25.66-b17, mixed mode)

Using the ubuntu ppa for oracle-java-8:

java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

I would assume, the string "java" at the beginning denotes Oracle Java, whereas the OpenJDK gets you "openjdk".

Sascha K
  • 101
  • 3
2

Call sun.misc.Version#println in java code will dump the version info to stderr. If you want to fetch the JDK version from java code.

package bj.tmp;

import sun.misc.Version;

public class Foo {
    public static void main(String[] args) {
        Version.println();
    }
}

Like this:

java version "1.8.0_192"
Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)
BaiJiFeiLong
  • 3,716
  • 1
  • 30
  • 28
2

Based on actual test I did on my system by using Oracle JDK and OpenJDK:

Option 1

  • You can execute the java –version command and in the case of OpenJDK you will clearly see “openjdk” in the output while in case of Oracle JDK you will se “Hotspot” in the output. That's how you can differentiate.
  • Below is actual from my system:

C:\Users\himanshu.agrawal>"C:\E_Drive\Softwares\OpenJDK-java-se-7u75-ri\jre\bin\java" -version
openjdk version "1.7.0_75"
OpenJDK Runtime Environment (build 1.7.0_75-b13)
OpenJDK Client VM (build 24.75-b04, mixed mode)

C:\Users\himanshu.agrawal>java -version
java version "1.8.0_301"
Java(TM) SE Runtime Environment (build 1.8.0_301-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.301-b09, mixed mode)

Option 2

  • You can use java.vm.name or java.runtime.name system property.
  • I think since Oracle is still the key contributor / responsible for the OpenJDK project so if you use java.vm.vendor or java.specification.vendor you still get Oracle as the vendor.
  • Below actual output from my system for these properties:

// when using OpenJDK
java.vm.name = OpenJDK 64-Bit Server VM
java.runtime.name = OpenJDK Runtime Environment
java.vm.vendor = "Oracle Corporation"
java.specification.vendor = Oracle Corporation

// when using Oracle JDK
java.vm.name = Java HotSpot(TM) 64-Bit Server VM
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.vendor = Oracle Corporation
java.specification.vendor = Oracle Corporation
hagrawal7777
  • 14,103
  • 5
  • 40
  • 70