How to Check Java Version

Java is one of the most widely used programming languages, and knowing your installed Java version is essential for ensuring compatibility with applications and development environments. This guide will walk you through various methods to check your Java version on different operating systems.

1. Checking Java Version on Windows

Using Command Prompt

1. Press Win + R to open the Run dialog.

How to Check Java Version

2. Type cmd and press Enter to open the Command Prompt.

How to Check Java Version

3. In the Command Prompt, type the following command and press Enter:

java -version

4. The installed Java version will be displayed. For example:

How to Check Java Version

Using Windows Settings (For Installed JDKs)

  1. Open the Start Menu and type “Environment Variables”.
  2. Click on “Edit the system environment variables.”
  3. In the System Properties window, click on the “Environment Variables” button.
  4. Under “System Variables,” check the JAVA_HOME variable, which typically points to the Java installation directory.
  5. Navigate to the directory, and check the version in the release file.

2. Checking Java Version on macOS

Using Terminal

1. Open the Terminal application. You can find it in Applications > Utilities or search for “Terminal” in Spotlight.

2. In the Terminal, type the following command and press Enter:

java -version

3. The installed Java version will be displayed. For example:

java version “11.0.15” 2022-04-19 LTS
Java(TM) SE Runtime Environment (build 11.0.15+10-LTS-191)
Java HotSpot(TM) 64-Bit Server VM (build 11.0.15+10-LTS-191, mixed mode)

3. Checking Java Version on Linux

Using Terminal

1. Open your terminal application.

2. Type the following command and press Enter:

java -version

3. The installed Java version will be displayed. For example:

openjdk version “1.8.0_352”
OpenJDK Runtime Environment (build 1.8.0_352-b08)
OpenJDK 64-Bit Server VM (build 25.352-b08, mixed mode)

Using Package Manager

For Debian-based systems (Ubuntu):

dpkg –list | grep -i jdk

For Red Hat-based systems (Fedora, CentOS):

rpm -qa | grep -i jdk

4. Alternative Methods to Check Java Version

Using an IDE

If you are using an Integrated Development Environment (IDE) like IntelliJ IDEA, Eclipse, or NetBeans:

  1. Open your IDE.
  2. Navigate to the settings or project configuration.
  3. Check the configured JDK version, which usually corresponds to the installed Java version.

Common Issues and Solutions

  1. Command Not Found:
    • If the java command is not recognized, Java may not be installed or properly added to the system’s PATH environment variable. Ensure you install Java and configure the PATH.
  2. Multiple Versions Installed:
    • Use the which java (Linux/macOS) or where java (Windows) command to locate the executable being used.
  3. JAVA_HOME Not Set:
    • Setting the JAVA_HOME environment variable can help tools and scripts locate your Java installation.

Conclusion

Checking your Java version is a simple yet important task for developers and users who work with Java-based applications. Whether you use the command line, settings, or an IDE, ensuring you have the correct version installed can save time and prevent compatibility issues. Follow the steps above based on your operating system to verify your Java installation quickly.

Share with friends

Leave a Comment

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