76

There are two varieties of JRE available. Java VM: IBM vs. Sun.

Is there a way to know which JRE I am using through JavaScript or some Java issued command.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
noquery
  • 1,895
  • 1
  • 15
  • 16

10 Answers10

199

The following command will tell you a lot of information about your java version, including the vendor:

java -XshowSettings:properties -version

It works on Windows, Mac, and Linux.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ernesto Iser
  • 2,524
  • 2
  • 13
  • 18
  • I don't know why people are not voting this one higher since it is the easiest to accomplish in windows and linux. Do you know if it works on Mac? – Ovi Jun 10 '15 at 20:56
  • 3
    Thanks for your comment, I just tried it on my mac and it doesn't work, good catch – Ernesto Iser Jun 10 '15 at 20:57
  • This command reports Oracle as my Java vendor in my Ubuntu system, despite it being OpenJDK actually. – clapas Nov 03 '15 at 11:58
  • @clapas could you please post the version of ubuntu that you are running and the command you used to install java? thanks – Ernesto Iser Nov 04 '15 at 20:05
  • @ErnestoIser Ubuntu 14.04. I installed Java through apt-get. – clapas Nov 05 '15 at 12:19
38
 System.out.println(System.getProperty("java.vendor"));
 System.out.println(System.getProperty("java.vendor.url"));
 System.out.println(System.getProperty("java.version"));

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

http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html

Frank
  • 1,479
  • 11
  • 15
  • 2
    This doesn't distinguish Oracle JRE from OpenJDK - see [this answer](https://stackoverflow.com/a/55002471/476716) – OrangeDog Mar 05 '19 at 12:08
31
  1. Open up your:
    • command prompt if you're using Windows
    • terminal if you're using mac or Linux
  2. Type in:

    java -version // This will check your JRE version
    javac -version // This will check your Java compiler version if you installed the JDK
    
  3. Grab a cup of coffee and you're done! You don't need to add the .exe to the java -version if everything is installed correctly.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
chaos_faction
  • 369
  • 2
  • 3
21

In Linux:

java -version

In Windows:

java.exe -version

If you need more info about the JVM you can call the executable with the parameter -XshowSettings:properties. It will show a lot of System Properties. These properties can also be accessed by means of the static method System.getProperty(String) in a Java class. As example this is an excerpt of some of the properties that can be obtained:

$ java -XshowSettings:properties -version
[...]
java.specification.version = 1.7
java.vendor = Oracle Corporation
java.vendor.url = http://java.oracle.com/
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
java.version = 1.7.0_95
[...]

So if you need to access any of these properties from Java code you can use:

System.getProperty("java.specification.version");
System.getProperty("java.vendor");
System.getProperty("java.vendor.url");
System.getProperty("java.version");

Take into account that sometimes the vendor is not exposed as clear as Oracle or IBM. For example,

$ java version
"1.6.0_22" Java(TM) SE Runtime Environment (build 1.6.0_22-b04) Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)

HotSpot is what Oracle calls their implementation of the JVM. Check this list if the vendor does not seem to be shown with -version.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Francisco Puga
  • 23,869
  • 5
  • 48
  • 64
  • java version "1.6.0_22" Java(TM) SE Runtime Environment (build 1.6.0_22-b04) Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing) – noquery Dec 12 '11 at 09:24
  • 1
    when you see hotspot, it's Sun Java. Sorry, it's Oracle Java now. – wyz Dec 12 '11 at 09:29
4

Open a command prompt:

 Version:  java -version
 Location: where java (in Windows)
           which java (in Unix, Linux, and Mac)

To set Java home in Windows:

Right click on My computerPropertiesAdvanced system settingsEnvironment VariableSystem VariableNew. Give the name as JAVA_HOME and the value as (e.g.) c:\programfiles\jdk

Select Path and click Edit, and keep it in the beginning as: %JAVA_HOME%\bin;...remaining settings goes here

JAVA_HOME

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
TechFind
  • 3,696
  • 18
  • 47
  • 62
  • thx for bringing up the connection between windows environment variables and the used binaries – D M Feb 19 '20 at 11:41
  • Six years after the question was asked and this does absolutely nothing to answer the question. – Mike Nov 02 '21 at 12:21
4

The Java system property System.getProperty(...) to consult is "java.runtime.name". This will distinguish between "OpenJDK Runtime Environment" and "Java(TM) SE Runtime Environment". They both have the same vendor - "Oracle Corporation".

This property is also included in the output for java -version.

OrangeDog
  • 36,653
  • 12
  • 122
  • 207
1

Git Bash + Windows 10 + Software that came bundled with its own JRE copy:

Do a "Git Bash Here" in the jre/bin folder of the software you installed.

Then use "./java.exe -version" instead of "java -version" to get the information on the software's copy rather than the copy referenced by your PATH environment variable.

Get the version of the software installation: ./java.exe -version

JMIM@DESKTOP-JUDCNDL MINGW64 /c/DEV/PROG/EYE_DB/INST/jre/bin
$ ./java.exe -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

Get the version in your PATH variable: java -version

JMIM@DESKTOP-JUDCNDL MINGW64 /c/DEV/PROG/EYE_DB/INST/jre/bin
$ java -version
java version "10" 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)

As for addressing the original question and getting vendor information:

./java.exe -XshowSettings:properties -version ## Software's copy
java       -XshowSettings:properties -version ## Copy in PATH
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
KANJICODER
  • 3,611
  • 30
  • 17
1

To check actually runned Java version you can use java.lang.Runtime API available since Java 10.

Runtime.Version version = Runtime.version();
int javaVersion = version.feature();
// returns 17 for Java 17
0

I had a problem where my Java applications quit work with no discernible evidence that I could find. It turned out my system started using the 64-bit version rather than the 32-bit version was needed (Windows Server 2012). In Windows, the command:

Javaw -version

just brought me back to the command prompt without any information. It wasn't until I tried

Javaw -Version 2>x.txt
type x.txt

that it gave me what was being executed was the 64-bit version. It boiled down to my PATH environment variable finding the 64-bit version first.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
SteveFerg
  • 3,466
  • 7
  • 19
  • 31
0

As you are expecting it to know using the Javascript, I believe you want to know the JRE versioned being used in your browser. Hence you can include Java version tester applet which can exactly tell you the version of the current browser.

import java.applet.*;
import java.awt.*;

public class JavaVersionDisplayApplet extends Applet
{
  private Label m_labVersionVendor;

  public JavaVersionDisplayApplet() // Constructor
  {
    Color colFrameBackground = Color.pink;
    this.setBackground(colFrameBackground);
    m_labVersionVendor = new Label (" Java Version: " +
                                   System.getProperty("java.version") +
                          " from "+System.getProperty("java.vendor"));
    this.add(m_labVersionVendor);
  }
}
Amit Kumar Gupta
  • 7,193
  • 12
  • 64
  • 90
  • What is *"JS"* in this context? *[JavaScript](https://en.wikipedia.org/wiki/JavaScript)*? *Java* something? Something else? (Respond by [editing your answer](https://stackoverflow.com/posts/8472187/edit), not here in comments (***without*** "[Edit:](http://meta.stackexchange.com/a/230693)" [or similar](http://meta.stackexchange.com/a/127655)). Thanks in advance.) – Peter Mortensen Feb 01 '20 at 23:39