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.
Table of Contents
1. Checking Java Version on Windows
Using Command Prompt
1. Press Win + R
to open the Run dialog.
2. Type cmd
and press Enter to open the Command Prompt.
3. In the Command Prompt, type the following command and press Enter:
java -version
4. The installed Java version will be displayed. For example:
Using Windows Settings (For Installed JDKs)
- Open the Start Menu and type “Environment Variables”.
- Click on “Edit the system environment variables.”
- In the System Properties window, click on the “Environment Variables” button.
- Under “System Variables,” check the
JAVA_HOME
variable, which typically points to the Java installation directory. - 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:
- Open your IDE.
- Navigate to the settings or project configuration.
- Check the configured JDK version, which usually corresponds to the installed Java version.
Common Issues and Solutions
- 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.
- If the
- Multiple Versions Installed:
- Use the
which java
(Linux/macOS) orwhere java
(Windows) command to locate the executable being used.
- Use the
- JAVA_HOME Not Set:
- Setting the
JAVA_HOME
environment variable can help tools and scripts locate your Java installation.
- Setting the
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.