How to Check Java Version in CMD: A Simple Guide


Java is a popular programming language used for many things, like building websites, creating Android apps, and even in scientific projects. To make sure everything works correctly, it's important to know which version of Java you have on your computer. In this guide, we'll show you how to check your Java version using the Command Prompt (CMD) in Windows.
Whether you are learning Java, working on a project, or just curious, knowing how to check your Java version is useful. We’ll also explain why it’s important to keep Java updated and how to fix common issues.
Why Should You Check Your Java Version?
Before we get into how to check your Java version, let’s talk about why it’s important to do so:
1. Compatibility: Some programs or tools need a certain version of Java to work properly. If you have the wrong version, they might not work.
2. Security: Java updates regularly to fix security problems. If you have an old version, your computer might be at risk.
3. Performance: New Java versions often run faster and better, which can make your programs work more smoothly.
4. Development: If you’re learning or building with Java, you need to make sure you have the right version of the Java Development Kit (JDK) to compile and run programs.
How to Check Java Version in CMD (Windows)
Let’s go through the steps to check which version of Java is installed on your Windows computer.
Step 1: Open Command Prompt
- Press the
Windows + R
keys on your keyboard. This will open the "Run" window.
2. Type cmd
in the box and press Enter. You can also search for “Command Prompt” in your Start menu.
A black window will open where you can type commands.
Step 2: Type the Java Version Command
Once you have the Command Prompt open, type the following command:
```bash
java -version
```
Press Enter, and you will see something like this:
```
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)
```
Here’s what this means:
- Java version: The first line tells you the version number, like 1.8.0_281
. This is the version of Java installed on your computer.
- Runtime Environment: This shows details about the Java Runtime Environment (JRE), which helps run Java programs.
- Java VM: This tells you about the Java Virtual Machine (JVM), which is needed to run Java applications.
If you see the version number, it means Java is installed and working correctly. If you see an error like this:
```
'java' is not recognized as an internal or external command, operable program or batch file.
```
This means Java is either not installed or it isn’t set up properly. Don’t worry—we’ll explain how to fix this later.
How to Check if the Java Development Kit (JDK) is Installed
If you are writing Java code, you also need to know if the Java Development Kit (JDK) is installed. The JDK includes tools like javac
, which is used to compile (build) Java code.
To check for the JDK, type this command:
```bash
javac -version
```
If the JDK is installed, you’ll see something like this:
```
javac 1.8.0_281
```
If you get an error instead, it means the JDK isn’t installed, or it’s not set up correctly.
How to Set the JAVA_HOME Environment Variable
Sometimes, you need to set up an environment variable called JAVA_HOME
to tell your computer where Java is installed. Here’s how you can do that.
Step 1: Find Where Java is Installed
First, you need to find the folder where Java is installed. To do that, type the following command in Command Prompt:
```bash
where java
```
This will show you the path, which looks something like this:
```
C:\Program Files\Java\jdk1.8.0_281\bin\java.exe
```
Step 2: Set the JAVA_HOME Variable
Now that you know where Java is installed, follow these steps to set the JAVA_HOME
variable:
1. Right-click on This PC
or Computer
and select Properties
.
2. Click on Advanced system settings
on the left.
3. In the new window, click Environment Variables
.
4. Under System variables
, click New
.
5. In the Variable name
field, type JAVA_HOME
.
6. In the Variable value
field, paste the path to where Java is installed (e.g., C:\Program Files\Java\jdk1.8.0_281
).
7. Click OK.
Once you’ve done this, your computer will know where to find Java when you use it in Command Prompt, PowerShell, or in an IDE (Integrated Development Environment) like Eclipse.
How to Install or Update Java
If you don’t have Java installed or need a newer version, here’s how to do it:
Step 1: Download Java
Go to the [official Oracle website](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html) and download the latest version of the JDK or JRE (depending on what you need). Make sure you choose the correct version for Windows, macOS, or Linux.
Step 2: Install Java
After downloading Java:
- Open the installer file and follow the instructions to install Java.
2. By default, Java will be installed in C:\Program Files\Java
.
3. After installation, Java should set up automatically, but you might need to set the JAVA_HOME
variable as explained earlier.
Step 3: Verify the Installation
Once Java is installed, open CMD and type:
```bash
java -version
```
If everything is working, you’ll see the version number.
Common Problems and How to Fix Them
Here are some common problems you might face when checking your Java version and how to fix them.
'java' is not recognized as an internal or external command
This error means Java isn’t installed, or the system path isn’t set correctly.
Solution: Reinstall Java and make sure the installation directory is added to the system’s PATH variable.
2.
Error: Could not find or load main class
This means there’s a problem with your classpath, which tells Java where to find files it needs to run.
- Solution: Check the CLASSPATH environment variable and make sure it’s set correctly.
3. Outdated Java Version
Some programs need the latest version of Java.
- Solution: Go to the Oracle website and download the latest version of Java to make sure everything works properly and safely.
Conclusion
Checking your Java version is an easy but important step, especially if you’re working on a project or learning Java. By following these steps, you can quickly find out which version of Java is installed on your system.
We also covered how to install Java, set the JAVA_HOME
variable, and fix common problems. By keeping Java up to date, you’ll improve security and performance, ensuring everything runs smoothly.
Now that you know how to check your Java version in CMD, you can confidently manage Java on your computer. If you run into any issues, leave a comment, and we’ll be happy to help!
Subscribe to my newsletter
Read articles from Steve directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
