42

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?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Mayank Kataria
  • 870
  • 2
  • 12
  • 22
  • 1
    First uninstall all the versions of Java, install Jdk 8. Open new command prompt and type java -version. – Sambit Aug 05 '19 at 17:33
  • 2
    If your JDK is on your path you should be able to tell by just running 'javac -version'. From the error you described it sounds like you're on Windows, so if the first command fails try executing (with the quotes) the following: "%JAVA_HOME%\bin\javac -version" – Alex Broadwin Aug 05 '19 at 17:36
  • @AlexBroadwin your method worked for me. But i've installed 8th version and in cmd "1.8.0_221" is coming. What does that mean? – Mayank Kataria Aug 05 '19 at 17:45

4 Answers4

35

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.

Valentyn Hruzytskyi
  • 1,772
  • 5
  • 27
  • 59
ganga
  • 402
  • 4
  • 5
  • Your method worked for me. But i've installed jdk version 8 and in cmd java version "1.8.0_221" is coming. What does that mean? – Mayank Kataria Aug 05 '19 at 18:02
  • 1
    It means you have JDK 8 installed – Kavitha Karunakaran Aug 05 '19 at 18:09
  • 3
    you are good, you have installed Java 8 and the _221 is just the update release(They keep on adding some features or there will be minor updates), for more info you can refer by clicking here https://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html – ganga Aug 05 '19 at 18:15
  • -version is useless: C:\Windows\system32>java -version java version "1.8.0_281" Java(TM) SE Runtime Environment (build 1.8.0_281-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode) – oOo Feb 17 '21 at 17:47
  • 3
    My java -version shows java version ```"15.0.2" 2021-01-19```. How do I find out what my JDK is? – JOSEPH Blessingh Mar 11 '21 at 12:31
  • Important detail : it's -version not --version or -v – kaios May 16 '22 at 12:10
9

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.

tarik
  • 312
  • 1
  • 9
  • 4
    java version vs jdk versions could be different ? Seems useless or confusing at best ! JDK, JSE, it's all a bit bloody mess – oOo Feb 17 '21 at 17:48
4

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.

Our_Benefactors
  • 3,220
  • 3
  • 21
  • 27
2

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. 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.

Woodchuck
  • 3,869
  • 2
  • 39
  • 70