- Java (JRE/JDK) – Check version installed
- Check JDK Version
- Check JRE Version
- Where JDK is installed?
- Check Java Version in Windows 10 (GUI)
- Check Java Version using PowerShell
- Check Java Version on Remote Computers (Powershell)
- How To Find and Verify Installed Java Runtime Version?
- Java or JRE Version Numbers
- Determine Java Version in Windows From Command Line
- Determine Java Version in Windows From GUI
- Determine Java Version Linux (CentOS, RedHat, Fedora, Ubuntu, Debian, Kali, Mint)
- Determine Java Version Online
- How do I find Java version?
- Using System Properties
- Using Runtime.version()
Java (JRE/JDK) – Check version installed
Firts of all, 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.
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
A common way to check JDK version is by using the following simple command to find out the version of the installed JDK. In the below example, the JDK version is 11.0.7:
Check JRE Version
Similarly, 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:
$ 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.
Where JDK is installed?
On Ubuntu or Linux system, we can use which javac to find out where JDK is installed:
$ 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/.
In addition, we can use Linux apt package manager (Debian/Ubuntu systems) to get info about installed Java:
sudo apt list --installed | grep -i openjdk
We can also list all installed packages and filter for Java using the dpkg command:
And below on RedHat/CentOS systems (obviously the java -version approach is still valid):
rpm -qi openjdk OR yum info "openjdk" OR yum list installed | grep -i openjdk
On Microsoft Windows, we can use dir /b /s javac.exe to find out where JDK is installed.
Microsoft Windows [Version 10.0.18362.900] (c) 2019 Microsoft Corporation. All rights reserved. C:\>dir /b /s javac.exe C:\Program Files\Common Files\Oracle\Java\javapath\javac.exe C:\Program Files\Common Files\Oracle\Java\javapath_target_52887656\javac.exe C:\Program Files\Java\jdk-11.0.12\bin\javac.exe C:\Program Files\Java\jdk1.8.0_271\bin\javac.exe
Or, alternatively, using Powershell:
Get-Childitem –Path C:\ -Include javac.exe -Recurse -ErrorAction SilentlyContinue
Check Java Version in Windows 10 (GUI)
You can get the version number of Java installed on your computer if you enter java in Windows 10 search box and run Java applet.
In About Java window, the current JRE version is specified. In this case, it is Java Version 8 Update 261 (build 1.8.0_261-b12). Note the value of the JRE build. All Java versions have 1 at the beginning followed by the number of major JRE version (it is 8 in this case) and the update number.
We can also check the current Java version in Windows Program and Features (Win+R -> appwiz.cpl).
Check Java Version using PowerShell
You can check Java version installed on your computer using PowerShell. You can just check the version of the executable file java.exe (the path to it is set in the environment variables when JRE SE is installed on your computer). Display the java file version:
Get-Command Java | Select-Object Version
We can view detailed information about Java version, update and release number:
Get-Command java | Select-Object -ExpandProperty Version Major Minor Build Revision ----- ----- ----- -------- 8 0 2610 12
If we want to get a string value of your Java JRE version to be used in scripts, use the command:
(Get-Command java | Select-Object -ExpandProperty Version).tostring()
If we want to specifically be sureabout the JDK version installed on the system, we can use the following Powershell command targeting the Java compiler, javac.exe:
(Get-Command javac | Select-Object -ExpandProperty Version).tostring()
We can also find out your Java version using WMI class Win32_Product (contains the list of installed programs in Windows):
Get-WmiObject -Class Win32_Product -Filter "Name like '%Java%'"
The IDs may be used later to correctly uninstall JRE.
If you want to display only Java version without Java Auto Updater, use the following command:
Get-WmiObject -Class Win32_Product -Filter "Name like '%Java%' and not Name like '%Java Auto Updater%'" | Select -Expand Version
Finally, we can dig directly into the Windows Registry, using Powershell, to get the actual installed version of both JRE and JDK packages with the following two commands:
dir "HKLM:\SOFTWARE\JavaSoft\Java Runtime Environment" | select -ExpandProperty pschildname -Last 1 dir "HKLM:\SOFTWARE\JavaSoft\Java Development Kit" | select -ExpandProperty pschildname -Last 1
Check Java Version on Remote Computers (Powershell)
If we want to get Java versions used on all computers or servers in your domain, you can use the following PowerShell script. The script can get the information from all servers remotely according to the list you enter manually or from a text file. You can also get the list of servers or computers in AD using the Get-ADComputer cmdlet from the RSAT-AD-PowerShell module.
# Check Java version against the list of servers in a text file #$computers=Get-content C:\PS\ServerList.txt # To get Java version on all Windows Servers in AD domain $computers = ((get-adcomputer -Filter < enabled -eq “true” -and OperatingSystem -Like ‘*Windows Server*’ >).name).tostring() Get-WmiObject -Class Win32_Product -ComputerName $computers -Filter “Name like ‘%Java%’ and not Name like ‘%Java Auto Updater%'” | Select __Server, Version
An additional, similar, way to get Java version info from remote systems, by using Powershell, is the following Invoke-Command approach:
$Servers = Get-Content 'C:\Server.txt' $ServersNotAvailable = @() $JavaVersion = < function GetJavaVersion() < Try < $ret = java -version 2>&1 | Select-String "version" | select @>,@> return $ret > Catch < $Prop = [ordered]@New-Object -TypeName psobject -Property $Prop > > GetJavaVersion > foreach($Server in $Servers) < $TestCon = Test-Connection -ComputerName $Server -Count 1 -Quiet if($TestCon) < Invoke-Command -ComputerName $Server -ScriptBlock $javaversion | Select Server,JavaVersion >else < $ServersNotAvailable = $Server + "," + $ServersNotAvailable >> ### Below is list of servers which are not available over the network or not pingable Write-Host "`nServers Not reachable over Network" -ForegroundColor Green $ServersNotAvailable
How To Find and Verify Installed Java Runtime Version?
Java Runtime Environment is used to run Java applications. Java Runtime Environment is called JRE. There are different versions of JRE most recent major versions are 6,7,8. Some of the applications generally require a different version because of comp ability problems. In this tutorial, we will look at how to get JRE or Java versions from various operating systems. If you want to learn JRE and differences with JDK please read the following tutorial.
Java or JRE Version Numbers
Java uses a bit different version numbers. All java versions first numbers is 1 actual major version numbers change according to release which is current 8 . Example Java version number is like below.
Determine Java Version in Windows From Command Line
We have different methods to determine Java or JRE version in windows. The first way is running java command in command line with version information. We will also provide -version option like below.
We can see that cırrent JRE or Java version is 1.8.0_144 . Here we can call 8 as a major version number.
Determine Java Version in Windows From GUI
We can use the Java menu which resides in the Control Panel.
And then In the General tab click to About button. This will open a new window that will provide information about the current Java or JRE version.
We can see and get the following information.
- Version 8 specifies the main version of Java which is 8 in this example.
- Update 144 specifies the minor version which numbered as 144.
Determine Java Version Linux (CentOS, RedHat, Fedora, Ubuntu, Debian, Kali, Mint)
We will use java command from the command line to get information about Java or JRE installation of Linux distributions.
We can see that a lot of information about Java and the platform is provided.
- openjdk version «1.8.0_131» is the current version of Java. We can see that the Java implementation is OpenJDK which is an open version of Java for Linux distributions.
- ubuntu is the operating system where Java is created.
- OpenJDK 64-Bit Server VM specifies the Java CPU architecture which is 64 bit.
Determine Java Version Online
We can also use the currently installed Java version from the web. We will navigate to the following URL which is provided by Oracle Java. We will see a screen like below. First, we will click on the Agree and Continue button.
For security reasons, current popular browsers have disabled the Java or JRE by default. So Google Chrome, Mozilla Firefox, etc. will show a warning like Java is disabled or not installed . If Java is enabled for browser we will see the current version of Java without a problem.
How do I find Java version?
The simplest way to get the Java version is by running the java -version command in your terminal application or Windows command prompt. If Java is installed and available on your path you can get information like below.
java -version java version "17" 2021-09-14 LTS Java(TM) SE Runtime Environment (build 17+35-LTS-2724) Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing)
Using System Properties
But if you want to get Java version from your Java class or application you can obtain the Java version by calling the System.getProperty() method and provide the property key as argument. Here are some property keys that related to Java version that you can read from the system properties.
package org.kodejava.lang; public class JavaVersion < public static void main(String[] args) < String version = System.getProperty("java.version"); String versionDate = System.getProperty("java.version.date"); String runtimeVersion = System.getProperty("java.runtime.version"); String vmVersion = System.getProperty("java.vm.version"); String classVersion = System.getProperty("java.class.version"); String specificationVersion = System.getProperty("java.specification.version"); String vmSpecificationVersion = System.getProperty("java.vm.specification.version"); System.out.println("java.version: " + version); System.out.println("java.version.date: " + versionDate); System.out.println("java.runtime.version: " + runtimeVersion); System.out.println("java.vm.version: " + vmVersion); System.out.println("java.class.version: " + classVersion); System.out.println("java.specification.version: " + specificationVersion); System.out.println("java.vm.specification.version: " + vmSpecificationVersion); >>
Running the code above give you output like the following:
java.version: 17 java.version.date: 2021-09-14 java.runtime.version: 17+35-LTS-2724 java.vm.version: 17+35-LTS-2724 java.class.version: 61.0 java.specification.version: 17 java.vm.specification.version: 17
Using Runtime.version()
Since JDK 9 we can use Runtime.version() to get Java runtime version. The feature() , interim() , update and patch() methods of the Runtime.Version class are added in JDK 10. These methods is a replacement for the major() , minor() and security() methods of JDK 9.
Below is the code snippet that demonstrate the Runtime.version() .
package org.kodejava.lang; public class RuntimeVersion < public static void main(String[] args) < System.out.println("Version: " + Runtime.version()); System.out.println("Feature: " + Runtime.version().feature()); System.out.println("Interim: " + Runtime.version().interim()); System.out.println("Update: " + Runtime.version().update()); System.out.println("Patch: " + Runtime.version().patch()); System.out.println("Pre: " + Runtime.version().pre().orElse("")); System.out.println("Build: " + Runtime.version().build().orElse(null)); System.out.println("Optional: " + Runtime.version().optional().orElse("")); >>
Running the code snippet above produce the following output:
Version: 17+35-LTS-2724 Feature: 17 Interim: 0 Update: 0 Patch: 0 Pre: Build: 35 Optional: LTS-2724
Here are the summary of outputs running the above code using some JDKs installed on my machine.
Version | Feature | Interim | Update | Patch | Pre | Build | Optional |
---|---|---|---|---|---|---|---|
10.0.2+13 | 10 | 0 | 2 | 0 | 13 | ||
11.0.6+8-LTS | 11 | 0 | 6 | 0 | 8 | LTS | |
12.0.2+10 | 12 | 0 | 2 | 0 | 10 | ||
13.0.2+8 | 13 | 0 | 2 | 0 | 8 | ||
14+36-1461 | 14 | 0 | 0 | 0 | 36 | 1461 | |
15.0.2+7-27 | 15 | 0 | 2 | 0 | 7 | 27 | |
17+35-LTS-2724 | 17 | 0 | 0 | 0 | 35 | LTS-2724 |
A programmer, recreational runner and diver, live in the island of Bali, Indonesia. Programming in Java, Spring, Hibernate / JPA. You can support me working on this project, buy me a cup of coffee ☕ every little bit helps, thank you 🙏