Verify Java Version in Windows, Linux and Mac

Free Java courses with 37 real-time projects - Learn Java

Java was introduced in 1995 by Sun Microsystems. Since then it has been a programming language widely used by programmers around the world. Java receives updates very often to improve its quality and introduce new features to it. It is important to verify if we have the latest version of java running on our computer or not. In this article, we will take a look at various methods to check and verify the version of java running on our computer across all the Operating Systems.

What is the Java Version?

Java consists of many different components which build up the complete programming language. The Java Runtime machine (JRE) consists of Java Virtual Machine(JVM) libraries and other files, and all of them together form the Java Development Kit(JDK). With each update, each of these files is changed or improved. Together they form the Java version. Each of Java’s components has a separate build number and version.

Why Is Java Updated?

Java is a popular programming language that is regularly updated to enhance its security, stability, and performance. These updates are necessary for a number of reasons:

  • Security: Java updates frequently patch security vulnerabilities. Outdated Java versions can be exploited by malicious actors to gain unauthorized access to your system or steal sensitive information. Keeping Java up to date significantly reduces this risk.
  • Performance: Java updates may include performance improvements that can make your Java programs run faster and more efficiently.
  • New Features: New Java updates introduce new functionalities and features that you can leverage in your applications.
  • Bug Fixes: Updates often include fixes for bugs that could be causing problems in your Java programs.

Java Version verification on Windows:

In windows, there are four ways to verify the java version, they are as follows:
1. Using Command Prompt.
2. Using Control Panel
3. Using Java System Class.
4. Using the Directories Method.

Verify Java Version Using Command Prompt:

1. Open Command Prompt from search or type cmd in the run application.

open command prompt

2. In command prompt, type java -version, this will show the proper version and release of java the computer is running.

type command in prompt

Java Version Verification Using Control Panel:

1. Open the control panel from the Start menu or desktop.

open control panel

2. From Control panel click on Programs

programs on control panel

3. Click on Java

java in control panel

4. Click on about, this will show all the information regarding java on the computer

about on control panel

Verify java Version Using Java System Class:

In the Java system class, there is a function getProperty() that verifies the version of Java JRE. The function accepts a key as an argument. The key is the name of the system property. The syntax of the method is:

public static String getProperty (String Key)

The function returns string value or null if there is no property with that key. It throws NullPointerException when there is a null key and IllegalArgumentException when there is an empty key.

Program to check Java Version:

package com.DataFlair.Verify;
public class JavaVerify
{
    public static void main(String args[])  
        {   
             System.out.println("Java Version for this Computer is: "+System.getProperty("java.version"));  
        }  
}

The output of the above Program:

java system class output

Java version verification using Directory Method:

This is the most simple way to check the java version. In this method, we simply type About Java in the start menu. It will take us to an application that will show the Java Version.

directory method cropped

Java Version verification on Linux:

In Linux, we can check the java version through the terminal. We have to write java -version and it will give the version and build number.

Linux Terminal Version check

Java Version verification on Mac:

1. Through Terminal

Like Linux, in mac also, we can check the java version by typing java -version in the terminal.

2. Through System Preference

Follow the below steps to verify java version on Mac through system preference:

1: Click on the apple logo on the upper left side of the screen.
2: Click on System Preferences
3: Launch Java Control Panel from the Java Icon.
4: Click on the General Tab from the Java Control Panel.
5: Click About. This will show the Java version you are currently running.

3. Through README.md

Press the Command button along with the spacebar. A pop up will open showing the README.md file. This file will contain the details about the java version of your system.

Java Version Verification Through Web:

We can check the java version present on the computer through the oracle website. It will Uninstall the older version of Java and install the newer version if any.

java web verify

Note: We should not confuse between JDK version and JRE version, the terminal of windows shows the JDK version, the system class shows JRE version.

Both of them together along with other components make up java. All the detailed information about the latest versions of each component can be found on the official java website by oracle.

Additional Tips:

  • It’s recommended to uninstall older versions of Java before installing a newer version.
  • Be aware of the difference between JDK (Java Development Kit) and JRE (Java Runtime Environment). The command prompt on Windows might show the JDK version, while the Java system class typically shows the JRE version. Both JDK and JRE, along with other components, contribute to the overall Java version.
  • You can find the latest Java version and detailed information about each component on the official Oracle Java website.

Conclusion:

In this article, we saw why it is important to keep java up to date and how to verify which version of java we have. There are different ways to check the version, all of them are listed above in the article.

If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *