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\favtuts>which javac
'which' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\favtuts>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.