Oct 18, 2023 3 min read

How to Check Java Version

Check Java Version with our step-by-step tutorial. Java is a popular programming language known for its versatility and portability.

Check Java Version
Table of Contents

Introduction

Before we begin talking about how to check Java version, let's briefly understand – What is Java?

Java is a popular programming language known for its versatility and portability. Created by Sun Microsystems, now owned by Oracle, Java is widely used in web development, mobile apps, and enterprise software.

Its key features include object-oriented programming, automatic memory management, and "write once, run anywhere" capability, allowing code to be executed on different platforms without modification. Java's wide adoption and vast community support make it an excellent choice for developers aiming for scalable and robust applications.

This tutorial outlines how to find out what version of Java is installed on your Linux system using the command line. This is useful for installing applications that require a specific version of Java.

Advantages of Java

  1. Portability: Java's "write once, run anywhere" ability allows code to be used on various platforms.
  2. Object-Oriented: It supports OOP principles, enabling modular and organized programming.
  3. Robust & Secure: Built-in safety features and error handling ensure reliable and secure applications.
  4. Versatile: Used for web, mobile, enterprise, and more, making it adaptable for various development needs.
  5. Huge Community & Libraries: A vast community and extensive libraries offer abundant resources and support for developers.

Java Versioning

Java employs semantic versioning. The following versioning scheme is used for production-ready releases:

MAJOR.MINOR.SECURITY

In Java 11.0.8, for instance, 11 is the major version, 0 is the minor version, and 8 is the security version.

  • MAJOR - Major releases include new features and functions.
  • MINOR - Minor releases include various bug fixes and compatible improvements.
  • SECURITY - Security releases contain essential security fixes.

Checking Java Version

To find out the version of Java is installed on your machine, simply run the java -version command:

java -version

The command will print the default Java version:

Output

openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu120.04)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu120.04, mixed mode, sharing)

In this example, our machine is running Java 11.0.8. It is possible that the version installed on your system is different.

If you receive the error message “java: command not found,” Java is not installed on your system. Depending on your Linux distribution, use one of the following guides to install Java:

The system may even have numerous versions of Java installed at the same time. Run the following command to see if your system has multiple Java installations:

sudo update-alternatives --config java

If you only have one Java installation, the output will be as follows:

Output

There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-11-openjdk-amd64/bin/java
Nothing to configure.

Otherwise, the command will show a menu where you can choose which version will be the default Java version if you have multiple Java installations:

Output

There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode

Press <enter> to keep the current choice[*], or type selection number:

Type the version number (the number in the Selection column) and press Enter to change the default Java version.

FAQs to Check Java Version

What does the java -version command display?

It displays the installed Java version, along with the build and runtime information.

Can I check the Java version through the Control Panel or System Preferences?

Yes, on Windows, you can find it in the Control Panel under Java, while on macOS, it's in System Preferences > Java.

Are there graphical tools to check the Java version?

Yes, various third-party tools like Java Version Checker offer a user-friendly way to check your Java version.

Can I check the Java version programmatically within a Java application?

Yes, you can use System.getProperty("java.version") to obtain the version programmatically.

Can I have multiple Java versions installed on my computer simultaneously?

Yes, you can have multiple Java versions coexisting, but you must manage the PATH/environment variables correctly.

What should I do if I have an outdated Java version?

You should update to the latest version to ensure security and performance improvements.

Is Java 32-bit or 64-bit installed on my system?

Use java -d64 -version to check for 64-bit and java -d32 -version for 32-bit.

Conclusion

You can easily find out what Java version is installed on your Linux system by typing java -version.

If you have any queries, feel free to drop a comment below, and we'll be happy to help.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.