Mayank Kataria
Mayank Kataria

Reputation: 1030

How to know the jdk version on my machine?

I have recently uninstalled JDK 11 and installed JDK 8. For confirmation, I want to check which JDK is installed on my Windows 10 machine. I typed java -version on cmd then get the error message

java is not recognized as an internal or external command

How to know which JDK version installed on my PC?

Upvotes: 57

Views: 389234

Answers (6)

jubair
jubair

Reputation: 11

if you are trying with this java -version

so that was not working!

Tryout this javac -version

Now i think it should be worked properly ..

Upvotes: 1

Mathias Hamp
Mathias Hamp

Reputation: 21

Java Runtime JRE and the Java development kit JDK are two separate things. If you want to check the version of the Java compiler used within your local JDK use javac -version. Note: if you use multiple JDKs the one that figures first a.k.a. above all others version you installed and referenced within your system path variables is applied. Hope this helps.

Upvotes: 0

Woodchuck
Woodchuck

Reputation: 4464

To get your jdk location in Windows, run this at a command prompt:

where java

This lists any and all locations of java.exe, including from your JAVA_HOME. For example, the 3rd line here reflects my JAVA_HOME location, where I'm pointing to JDK 8:

C:\Users\me> where java
C:\Program Files\Common Files\Oracle\Java\javapath\java.exe
C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
C:\Program Files\Java\jdk1.8.0_202\bin\java.exe

Note for comparison that java -version does not reflect my JAVA_HOME location and in fact shows java version 11 instead of 8:

C:\Users\me> java -version
java version "11.0.15" 2022-04-19 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.15+8-LTS-149)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.15+8-LTS-149, mixed mode)

This is confusing because my Java compiles (e.g., via mvn) use JDK 8 since that's what my JAVA_HOME is pointing to. (I'm not even sure where the version 11 it found came from; possibly from when I installed maven.)

Determining the difference between the JRE and JDK you're running has never been straightforward. Seems like java -version used to be a way to do this, but no longer.

Adding to the complexity, you can also supposedly get your Java version info from Control Panel > Programs > Java > About. For me, that shows Version 8. That's despite java -version showing version 11.0.15. And it doesn't change even if I point my JAVA_HOME to JDK 11.

Note that this answer is also helpful. In my case, that helped me determine that I have java.exe and javac.exe at C:\Program Files (x86)\Common Files\Oracle\Java\javapath and C:\Program Files\Common Files\Oracle\Java\javapath. For best results, it seems like you should delete these from your Path variable if you're using a non-Oracle version, such as openjdk.

Depending on which one I have listed first in my Path variable, I get different results when i run java -version or java --version. The former seems to work when Java 8 is listed first; the latter when Java 11 is first.

Upvotes: 7

Our_Benefactors
Our_Benefactors

Reputation: 3539

On Windows 10, this required mapping the environment variable for JAVA_HOME to the JDK installation directory. Use these steps:

  1. Run the installer for the JDK. (available for windows here: https://www.oracle.com/java/technologies/downloads/#jdk17-windows)

  2. windows key -> Environment Variables, select the only result

  3. In the System Properties window that opened, select Environment Variables enter image description here

  4. Select new button under the User variables section

  5. Variable name: JAVA_HOME, Variable Value: <The JDK filepath from step 0>

  6. ok all open menus

  7. Close any open cmd prompt windows

  8. open a new cmd window and type echo %JAVA_HOME% It should print the installation path for the JDK.

Upvotes: 4

tarik
tarik

Reputation: 312

You need to update your Windows path to include your %JAVA_HOME%\bin directory. %JAVA_HOME% is the directory that you installed Java into and is also an environment variable that you need to configure for command line execution of your applications. You can edit both of these in the Windows control panel and you should restart.

When you run java -version you will see the internal version number. This is explained here: https://en.wikipedia.org/wiki/Java_version_history.

Basically, you can ignore the 1. when reading version number. The _xxx is a reference to the most recent patch or build release.

Upvotes: 9

ganga
ganga

Reputation: 512

you might need to add path in environment variables which you can find in Control Panel open the Jdk where you installed and add until /bin in the path in environment variables.

Add until /bin in path variable in System Variables which is residing in Environment Variables.

Then do java -version which might show up.

If still problem persists, try restarting your pc and see.

Upvotes: 46

Related Questions