zeroTutorials

Java, Server, Database Tutorials

Have a Question?

If you have any question you can ask below or enter what you are looking for!

Check JDK and JRE versions and installation locations

1. Difference between JDK and JRE :

The JRE is the Java Runtime Environment. It is a collection of everything needed to run a compiled Java program, including the Java Virtual Machine (JVM), Java class library, java command, and other frameworks. However, it cannot be used to create new programs.

The JDK is the Java Development Kit, the complete SDK for Java. It has everything the JRE has, but also compiler (javac) and tools (like javadoc and jdb). It is able to create and compile programs.

Usually, if you only care about running Java programs on a computer, you will only install the JRE. That’s all you need. On the other hand, if you plan to do Java programming, you should install the JDK instead.

The JRE is, as the name implies, an environment. It’s basically a bunch of directories with Java-related files, to wit:

The JDK is also a set of directories. It is a superset of the JRE, with some additions:

2. Check JDK Version :

In order to check the JDK version, we use the javac command since javac belongs to the JDK :

$ javac -version
javac 11.0.7

3. Check JRE Version :

In order to check the JRE version, we use the java command since java belongs to the JRE :

$ java -version
java version "1.8.0_341"
Java(TM) SE Runtime Environment (build 1.8.0_341-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.341-b10, mixed mode)

4. Find the installation location of the JDK :

a. On linux :

On Linux, one can use the command which javac in order to know the installation location of the JDK:

$ which javac
/usr/bin/javac

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

$ ls -l /etc/alternatives/javac
/etc/alternatives/javac -> /usr/lib/jvm/java-11-openjdk-amd64/bin/javac

b. On Windows :

If we use run where javac command, we can find many locations :

C:\>where javac
   C:\Program Files\AdoptOpenJDK\jdk-11.0.7.10-hotspot\bin\javac.exe
   C:\Program Files\Java\jdk1.8.0_202\bin\javac.exe

In order to check which JDK installation is used, we must run the command below :

C:\>for %i in (javac.exe) do @echo.   %~$PATH:i
   C:\Program Files\AdoptOpenJDK\jdk-11.0.7.10-hotspot\bin\javac.exe

5. Find the location of the JRE :

a. On linux :

On Linux, one can use the command which java in order to know the installation location of the JRE :

$ which java
/usr/bin/java

$ ls -l /usr/bin/java
/usr/bin/java -> /etc/alternatives/java

$ ls -l /etc/alternatives/java
/etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java

b. On Windows :

On Windows, If we run where java command, we can find many locations :

C:\>where java
C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
C:\Program Files\AdoptOpenJDK\jdk-11.0.7.10-hotspot\bin\java.exe
C:\Program Files\Java\jdk1.8.0_202\bin\java.exe

In order to check which JRE installation is used, we must run the command below :

C:\>for %i in (java.exe) do @echo.   %~$PATH:i
   C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
Tags:  ,