Main Tutorials

How to check JDK version that installed on your computer

check JDK version

The Java development kit (JDK) contains tools for Java development, and the Java Runtime Environment (JRE) contains a JVM to convert byte code .class to machine code, and execute it, in short, the JRE runs Java program.

Check JDK Version
We can use javac -version to find out the version of the installed JDK. In the below example, the JDK version is 11.0.7

Terminal

$ javac -version

javac 11.0.7

Check JRE Version
We can use java -version to find out the version of the installed JRE. In the below example, the JRE version is 1.8.0_252

Terminal

$ java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~19.10-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

The JDK and JRE versions can be different on the same computer. Multiple JDK and JRE versions are allowed on the same computer; it is better to find out which version is configured in the system classpath to run or compile the Java program.

1. Where JDK is installed?

The JDK also contains a JRE to run the Java program.

Terminal

$JAVA_HOME/bin/java     <-- JDK
$JAVA_HOME/jre/bin/java <-- JRE

1.1 On Ubuntu or Linux, we can use which javac to find out where JDK is installed.

Terminal

$ which javac
/usr/bin/javac

$ ls -lsah /usr/bin/javac
/usr/bin/javac -> /etc/alternatives/javac

$ ls -lsah /etc/alternatives/javac
/etc/alternatives/javac -> /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/bin/javac

$ cd /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/bin/
$ ./javac -version
javac 11.0.7

In the above example, the JDK is installed at /usr/lib/jvm/adoptopenjdk-11-hotspot-amd64/.

1.2 On Windows, we can use where javac to find out where JDK is installed.

Terminal

Microsoft Windows [Version 10.0.18362.900]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\mkyong>which javac
'which' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\mkyong>where javac
C:\opt\jdk-11.0.1\bin\javac.exe

Do I need JDK or JRE?
For end-users, they need to install JRE to run the Java program, and the JDK is for developers. For the production environment, the deployment team only need to install JRE to run the Java program. However, developers often request to install the JDK, instead of the standalone JRE on the production server, because the JDK contains JRE and also extra tools to monitor and debug the running Java program.

References

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
32 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Ivan Soto
8 years ago

What’s up with this? The Java development kit (JDK) is NOT the same thing as the Java runtime environment (JRE). The java command gives the version of the JRE, the runtime environment. “javac -version” would give you the version of the Java development kit. *** I see that “Vittorio” had pointed this issue out already.

surendar
3 years ago
Reply to  Ivan Soto

yes you’re correct

Get It Right
9 years ago

“java -version” will only show you your version of JRE. “javac -version” will show you your version of JDK. Why the distinction? Some people might have only JRE installed and not JDK. JDK is just for programmers.

yasitha
7 years ago
Reply to  Get It Right

thanks

Nikhil
9 years ago

This is the wrong way of checking the java version. It will give you the JRE version installed on your machine and not the JDK version installed. Do you have any way of checking the JDK version installed on the machine.

Vittorio
11 years ago

wrong. that gives you the version of the JRE in your path.
if you want to have the JDK version you have to go to the jre/bin folder in your JDK and run the local file java version.

Linux example:

get the java version in my PATH:
vittorio@vittorio-laptop ~ $ java -version
java version “1.6.0_35”
Java(TM) SE Runtime Environment (build 1.6.0_35-b10)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01, mixed mode)

get the JDK version:

1) go to the jre/bin:
vittorio@vittorio-laptop ~ $ cd /usr/java/jdk/jre/bin

2) get the JDK version
vittorio@vittorio-laptop /usr/java/jdk/jre/bin $ ./java -version
java version “1.6.0_33”
Java(TM) SE Runtime Environment (build 1.6.0_33-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03, mixed mode)

as you can se they are different

Mani
11 years ago
Reply to  Vittorio

The JDK version is the same as “java version”

jim
10 years ago
Reply to  Mani

Yes, right. I’ve already install netbeans 7.3.1 but when I install glassfish, it said that my JDK Version still 6 version, need to install JDK 7. So it confusing me. Can somebody help me here?

Vittorio
11 years ago
Reply to  Mani

you can keep repeating stuff, it doesn’t become true for that 🙂

padro
10 years ago
Reply to  Vittorio

Vittorio for president.

It’s very important to note that JDK and JRE are different entities. Different versions. Different paths.

Gaurav khurana
9 years ago

thanks a lot ,, your answer is the correct we should go to that directory and can find the difference

kkeera
8 years ago

error: Could not load or find the main Class version

Deniz
9 years ago

I use 64 bit os and java -version show 64 bit jdk but installed 32 bit jdk. How to change of jdk version to 32 bit.

dinesh kumar
9 years ago

thank you so much.. it worked for me

krishna
10 years ago

hai
i am getting this error, while i running programming

Error: opening registry key ‘SoftwareJavaSoftJava Runtime Environment’

Error: could not find java.dll

Error: Could not find Java SE Runtime Environment.

Nikhil
9 years ago
Reply to  krishna

This is because the JRE is not installed on your machine.

swap
10 years ago

thanks a lot ….. 🙂 can we have more than one jdk running at the same time ? what is difference between jdk , jre , jinitiator , jvm ??? ple elaborate in simple manner..

swap
10 years ago

thanks a lot ….. 🙂 can we have more than one jdk running at the same time ? what is difference between jdk , jre , jinitiator , jvm ??? ple elaborate in simple manner.

Steve Witham
10 years ago

The title of this post says, “How to find the JDK version,” but recent JDK versions are like 6 or 7. Once I find the “1.x.y” version number, am I supposed to just strip off the “1.” part?

Vanathy Balaji
8 years ago
Reply to  Steve Witham

Yes. When the version is displayed as 1.8.0_31. It means JDK version 8, update 31.
the version of the JDK can be easily retrieved from the control panel programs information.

Paulami
10 years ago

Thanks it helped

vijay
10 years ago

thank you

Pandarinath
11 years ago

Thanks dear for simple solution. It helped.
Regards
SP

lee
11 years ago

huh didnt work for mine god knows why 🙁

Vittorio
11 years ago
Reply to  lee

because it can’t find the java command in your PATH

Sneha
6 years ago
Reply to  Vittorio

You can ignore, it worked.

Ramakrishna
6 years ago
Reply to  Sneha

Hi how can we get JDK versionit is showing like 7.0-internal how would i know full version number like .0.*.*

Sneha
6 years ago
Reply to  Vittorio

Same error for me. How do I fix this? It states java or javac is not recognised as an internal or external command

ren
11 years ago

Thanks….

User
11 years ago

Gr8
Its work for me
i am searching this solution since long time

thanks

ashok
11 years ago

hi dear
thanks its working ,its saved my log of time

Thanks
saraswatipgcollege.com