- 1 1. What You’ll Learn in This Article (Bottom Line Up Front)
- 2 2. Start Here: Java Version Check Command List (Copy & Paste)
- 3 3. How to Read java -version (Sample Output and How to Interpret It)
- 4 4. How to Read javac -version (Confirm Whether the JDK Is Installed)
- 5 5. How to Check the Java Version on Windows
- 5.1 5.1 Check Using Command Prompt / PowerShell (Basic)
- 5.2 5.2 A Windows-Specific Key Command: where java
- 5.3 5.3 Why an Old Java Version Is Used Even After Installation
- 5.4 5.4 How to Check JAVA_HOME (Windows)
- 5.5 5.5 Safe Checklist for Windows
- 5.6 5.6 Checking via the GUI (Environment Variables Screen) Can Wait
- 6 6. How to Check the Java Version on macOS
- 7 7. How to Check the Java Version on Linux
- 8 8. Why the Displayed Java Version Differs (Causes and Fixes)
- 9 9. A Checklist to Go Beyond Just “Checking”
- 10 10. FAQ (Frequently Asked Questions)
1. What You’ll Learn in This Article (Bottom Line Up Front)
On this page, we’ll organize the fastest way to achieve your goal of “checking the Java version from the command line.”
To share the conclusion first, the commands you’ll usually use are these two:
- The Java version that actually runs →
java -version - The JDK (compiler) version for development →
javac -version
However, in real-world environments, it’s very common to find that “the version you expected isn’t what shows up.”
This article doesn’t just list commands—it also explains why the mismatch happens and how to fix it.
1.1 What You’ll Be Able to Do After Reading
By the end, you’ll be able to do the following:
- Check your Java version immediately
- Confidently use
java -versionandjavac -versionfor the right purpose
- Confidently use
- Understand how to check on Windows / macOS / Linux
- Verify Java while accounting for common OS-specific differences
- Identify which Java is being used even when multiple versions are installed
- Troubleshoot “I installed it, but an older version still shows up” on your own
- Understand the typical causes and fixes when the version shown isn’t what you expected
- Learn the basics of PATH, JAVA_HOME, and version switching settings
1.2 Intended Audience (Beginners Welcome)
- You need to use Java and want to know which Java is installed on your PC first
- You’ve been told “Java 17 required” or “Java 8 only,” and you need to check your current version
- You ran a command and got a different version than you expected, and you’re stuck
javaworks butjavacdoesn’t, and you don’t fully understand JRE/JDK differences
1.3 One Key Point to Know Up Front (Very Important)
Most confusion about checking the Java version comes down to this one point:
- “Java installed on the machine” is not the same as “Java that actually runs.”
When multiple Java installations exist, the Java that runs is the one found in the highest-priority location at runtime.
That’s why the result of java -version may not be “the latest version you just installed.”
With that mismatch in mind, this article explains, in order:
- What to run first (the shortest path)
- What to check next to identify the cause (investigation steps)
- How to fix it (resolution steps)
step by step.
2. Start Here: Java Version Check Command List (Copy & Paste)
You don’t need many commands to check your Java version.
If you remember only this section, you’ll solve about 90% of cases.
2.1 Check the Java Version Used at Runtime
java -versionThis command shows the version of Java that actually runs on this PC right now.
It’s the most basic—and most important—way to confirm your Java environment.
What the Output Typically Includes (Example)
- The Java version number (e.g., 17 / 21 / 1.8, etc.)
- The implementation (OpenJDK / Oracle JDK, etc.)
- Runtime environment details such as 64-bit / Server VM
The key point is this: it targets the java that has the highest priority on your PATH.
It’s not about “where you installed Java,” but “which Java is being invoked.” Keep that in mind.
2.2 Check the Java Development Environment (JDK) Version
javac -versionThis command shows the version of the Java compiler (javac).
What This Tells You
- Whether the JDK is installed correctly
- Whether you can use Java not only for running apps, but also for development/builds
If this command shows something like:
- “command not found”
- “
javacis not recognized as an internal or external command”
then it’s very likely that the JDK isn’t installed or that your PATH isn’t set correctly.
2.3 The Difference Between java -version and javac -version (Common Beginner Confusion)
| Command | What It Checks | Main Use |
|---|---|---|
java -version | Java at runtime | Running apps / verifying runtime behavior |
javac -version | Compiler (JDK) | Development / builds |
A common misunderstanding is:
- If
java -versionworks, you can develop Java code.
This is not correct. - Run only →
java - Develop (compile) →
javac
These two have different roles, so checking both is the standard approach.
2.4 Check Using a JDK Tool (Optional)
Depending on your environment, you can also check the JDK version using the following command:
jshell --versionjshellis a tool included by default in JDK 9 and later- If this works, it’s a good sign that the JDK is installed
That said, as long as you understand java -version and javac -version, that’s usually enough.
2.5 Recommended Order to Check (Beginner-Friendly)
If you’re new to this, checking in the following order reduces confusion:
java -version
→ Check the Java version used at runtimejavac -version
→ Confirm the development JDK is available- If the results aren’t what you expected, see the next section for OS-specific checks
3. How to Read java -version (Sample Output and How to Interpret It)
In this section, we’ll break down what appears when you run java -version, step by step so beginners won’t get lost.
This is to prevent the common situation of “I don’t know what I’m supposed to look at.”
3.1 The Basic Role of java -version
java -version
What this command tells you is the Java version that will run right now.
It does not show a list of installed Java versions—it shows the one actually being used.
That’s why this result becomes the baseline for things like:
- Whether you meet the Java version required by an app or tool
- Whether production/test environments are running the intended Java version
- Whether an older Java version is being used unexpectedly
3.2 Typical Output Example (Illustration)
The exact wording varies by environment, but you’ll generally see something like this:
java version "17.0.8"
Java(TM) SE Runtime Environment (build 17.0.8+9)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.8+9, mixed mode)Within this output, the most important part is the first line.
3.3 What to Check First (This Is All You Need)
① Version Number
java version "17.0.8"17→ Java 17 series1.8.x→ Java 821.x→ Java 21
In many workplaces, LTS (Long-Term Support) releases like 8 / 11 / 17 / 21 are commonly used.
First, confirm whether it’s the major version your project requires.
② Java Distribution (Oracle / OpenJDK, etc.)
Java(TM) SE Runtime Environmentor
OpenJDK Runtime EnvironmentIn most cases, you don’t need to be overly strict about this for basic verification.
However, some companies/projects may explicitly require “Oracle JDK” or “OpenJDK,” so it can matter depending on your environment.
③ “64-Bit” / “Server VM”
64-Bit Server VM- In most modern environments, 64-Bit is normal
- Unless you have a special reason, a quick check here is enough
3.4 Why You Get “A Different Java Version Than Expected”
This is the point that confuses beginners the most.
A Common Misunderstanding
- “I installed the latest Java.”
- “So
java -versionshould show the latest version.”
In reality, this is not guaranteed.
The reason is simple:
java -versionruns
the firstjavait finds with the highest priority on PATH
That’s why.
In other words, if:
- An older Java remains earlier in PATH
- Multiple JDK/JRE installations are mixed together
then a different Java than the one you installed may run.
3.5 java -version Checks the “Result,” Not the “Location”
As an important way of thinking:
- ❌ Where Java is installed
- ⭕ Which Java is actually being executed
That’s what java -version is for.
First, simply decide whether the displayed result is correct.
If it’s not, use the following sections to identify the cause and fix it—that’s the safest workflow.
4. How to Read javac -version (Confirm Whether the JDK Is Installed)
Here we’ll explain the role of javac -version and how to interpret it.
Understanding this command quickly resolves a common issue: “Java runs, but I can’t develop/build.”
4.1 What Is javac? (Beginner-Friendly)
javac is short for Java Compiler.
java
→ runs an already-built programjavac
→ compiles source code (.java)
So the roles are:
- If you only want to run Java →
javais enough - If you want to develop/build Java →
javacis required
That’s the basic division of responsibilities.
4.2 What You Learn from javac -version
javac -versionThis command shows the version of the Java compiler currently being used.
Sample Output (Illustration)
javac 17.0.8The number shown here can be treated as:
- The JDK version itself
- The baseline Java version used for compilation in practice
That understanding is sufficient in most real-world situations.
4.3 Important Notes When It Doesn’t Match java -version
This kind of mismatch happens frequently in real work:
java -version→ 17javac -version→ 11
In that case, you have a mismatched setup:
- Runtime: Java 17
- Development: Java 11
Problems This Mismatch Can Cause
- You can’t use newer language features
- The build succeeds, but runtime errors occur
- Behavior differs between CI and local environments
So, as a basic policy, it’s safest to align both versions.
4.4 When javac Isn’t Found (Common Errors)
You may see messages like the following:
- “
javacis not recognized as an internal or external command” - “command not found: javac”
In this case, the likely causes are almost always one of these two:
Cause 1: The JDK Isn’t Installed
- Only the JRE (runtime) is installed
- Development tools are not included
Cause 2: PATH Isn’t Set
- The JDK is installed, but the
bindirectory is not included in PATH
You can reliably distinguish between these in the OS-specific confirmation sections.
4.5 javac -version Is a Signal of “Can I Develop?”
If you’re a beginner, remembering it like this will prevent confusion:
java -version
→ Can I run Java?javac -version
→ Can I develop/build Java?
If both commands show the expected versions,
your Java environment is in a state where the minimum necessary setup is complete.
5. How to Check the Java Version on Windows
This section explains how to check the Java version on Windows, including points that commonly cause trouble in real-world use.
Because Windows is an OS where multiple Java installations often coexist, the order of checks is especially important.
5.1 Check Using Command Prompt / PowerShell (Basic)
First, start with the most basic method.
- Open Command Prompt or PowerShell
- Run the following command
java -versionIf you plan to develop with Java, also check this:
javac -versionAt this point:
- If both versions are as expected
→ No problem - If the version is not what you expected
→ Identify the cause in the next steps
That’s how you should judge the result.
5.2 A Windows-Specific Key Command: where java
On Windows, it’s extremely important to identify which java.exe is actually being used.
where javaExample Output (Illustration)
C:\Program Files\Java\jdk-17\bin\java.exe
C:\Program Files\Common Files\Oracle\Java\javapath\java.exeIf multiple lines are shown, the one listed at the top has the highest priority and is what actually runs.
5.3 Why an Old Java Version Is Used Even After Installation
Common causes on Windows include:
- An older Java installation is still present
javapathappears earlier in PATH- JAVA_HOME and PATH do not match
In particular, if the following directory is included in PATH:
C:\Program Files\Common Files\Oracle\Java\javapathit often causes an unintended Java version to be invoked.

5.4 How to Check JAVA_HOME (Windows)
Next, check JAVA_HOME.
echo %JAVA_HOME%- If nothing is shown
→ JAVA_HOME is not set - If an unexpected path is shown
→ It may be pointing to an old Java version
Example of a Correct Setting
C:\Program Files\Java\jdk-17Note that it should point to the JDK root directory, not the bin directory.
5.5 Safe Checklist for Windows
For beginners, checking in this order helps avoid confusion:
java -versionjavac -versionwhere javaecho %JAVA_HOME%
If all four checks look correct,
you can conclude that your Java environment on Windows is properly configured.
5.6 Checking via the GUI (Environment Variables Screen) Can Wait
Windows also provides a GUI screen for viewing and editing environment variables, but:
- Which Java is being used
- Why there is a mismatch
are judged far more accurately using command output.
Use the GUI when you need to fix settings,
but always verify with commands—that’s the practical approach.
6. How to Check the Java Version on macOS
This section explains how to check the Java version on macOS.
Unlike Windows, macOS has a system-level mechanism for managing JDKs, so knowing the dedicated commands helps avoid confusion.
6.1 Check the Basic Commands in Terminal
First, start with the same basic commands used everywhere.
- Open Terminal
- Run the following command
java -versionIf you plan to develop with Java, also check:
javac -versionIf these two results are as expected,
the Java environment actually being used on macOS is fine.
6.2 Note: macOS Automatically Manages JAVA_HOME
On macOS, it’s common not to hard-code JAVA_HOME,
but instead to retrieve it dynamically using a system command.
The representative command is:
/usr/libexec/java_homeExample Output (Illustration)
/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/HomeThis path is the home directory of the current default JDK.
6.3 List Installed JDKs
If multiple JDKs are installed, the following command is extremely useful:
/usr/libexec/java_home -VRunning this command displays:
- Installed JDK versions
- Vendors (Oracle / OpenJDK-based, etc.)
- Supported architectures
On macOS, this is the safest way to first confirm what JDKs are actually installed.
6.4 When java -version and java_home Don’t Match
You may encounter a situation like this:
/usr/libexec/java_home→ Java 17java -version→ Java 11
In such cases, the likely causes are:
JAVA_HOMEis fixed in shell config files (.zshrc/.bashrc)- A different Java appears earlier in PATH
- A Homebrew-installed Java is taking priority
On macOS, user-level settings take precedence,
so shell configuration files have a strong influence.
6.5 Safe Checklist for macOS
On macOS, checking in this order keeps things organized:
java -versionjavac -version/usr/libexec/java_home/usr/libexec/java_home -V
With these four checks, you can accurately understand:
- The Java currently in use
- The list of installed Java versions
- The default JDK
without ambiguity.
6.6 Think in Terms of “Switching” on macOS
On macOS, it’s common that:
- Different projects require different Java versions
- You switch between multiple JDKs
Therefore:
- Don’t assume there’s only one Java
- Always confirm which Java is currently in use
Keeping this mindset makes it much easier to avoid trouble.
7. How to Check the Java Version on Linux
This section explains how to check the Java version on Linux environments, especially for server use.
While management methods differ by distribution, the core concepts are the same.
7.1 Start with the Basic Commands
On Linux as well, begin with the common commands:
java -versionIf development or builds are required, also check:
javac -versionWith these two commands, you can determine whether:
- The Java used at runtime
- The JDK used for compilation
match your expectations.
7.2 Use which java to Find the Actual Binary
On Linux, it’s important to know which executable is actually being invoked.
which javaExample Output
/usr/bin/javaThis path is the actual Java binary used by java -version.
If you need more detail, run:
ls -l $(which java)This lets you trace the symbolic link to its real target.
7.3 Managing Multiple Java Versions on Debian / Ubuntu (update-alternatives)
On servers, it’s very common to have multiple Java versions installed.
On Debian/Ubuntu-based systems, these are often managed with update-alternatives.
List Java Alternatives
update-alternatives --list javaCheck the Current Selection
update-alternatives --display javaThe path shown here is the Java selected at the system level.
7.4 When java -version and alternatives Don’t Match
Occasionally, you may see a mismatch such as:
update-alternatives→ Java 17java -version→ Java 11
Possible causes include:
- A different Java appears in the user’s PATH
- A manually installed Java exists in
/usr/local/bin, etc. - PATH differs between normal execution and
sudo
On Linux, both:
- System-level settings
- User-level environment
can influence which Java runs.
7.5 Safe Checklist for Linux
On Linux, checking in this order keeps things clear:
java -versionjavac -versionwhich javaupdate-alternatives --display java(if applicable)
This gives you a complete picture of:
- The Java currently running
- The actual executable file
- The system configuration
at a glance.
8. Why the Displayed Java Version Differs (Causes and Fixes)
Most Java version issues are caused not by the commands themselves, but by environment configuration.
Here we summarize causes that apply across all operating systems.
8.1 Cause 1: PATH Priority Is Not What You Expect
This is the most common cause.
- An old Java
bindirectory appears earlier in PATH - You installed a new Java but didn’t update PATH
How to Fix It
- Identify which Java is actually running
- Remove unnecessary PATH entries or fix their order
Simply “adding” a new path is often not enough.
8.2 Cause 2: JAVA_HOME Doesn’t Match the Running Java
- JAVA_HOME → Java 11
- Running Java → Java 17
This situation is also very common.
How to Fix It
- Set JAVA_HOME to the JDK root directory
- Ensure PATH uses
$JAVA_HOME/bin
Think of JAVA_HOME as a “reference,” and PATH as the “execution priority.”
8.3 Cause 3: java and javac Use Different Versions
This is a classic case of mixed JRE and JDK versions.
- Runtime works
- Development or builds fail
How to Fix It
- Choose one JDK as the standard
- Align
javaandjavacunder the same JDK
8.4 Cause 4: IDE or Build Tools Use a Different JDK
- Everything looks fine in the terminal
- Errors occur in the IDE or CI
In these cases, the cause is often IDE-specific JDK settings.
How to Fix It
- Explicitly check the JDK used in the IDE settings
- Don’t rely solely on “auto-detection”
9. A Checklist to Go Beyond Just “Checking”
Finally, let’s organize what you should do after checking your Java version.
9.1 If Your Goal Is Only to Run Java
- Does
java -versionmeet the requirements? - Does the application start correctly?
9.2 If Your Goal Is Development or Builds
- Does
javac -versionmeet the requirements? - Do
javaandjavacshow the same version? - Are JAVA_HOME and PATH aligned?
9.3 If You Use Multiple Java Versions
- Always confirm which Java is currently in use
- Understand OS-specific management (macOS / Linux)
10. FAQ (Frequently Asked Questions)
10.1 What’s the Difference Between java -version and javac -version?
java -version checks the Java runtime version,
while javac -version checks the development compiler (JDK) version.
Since they serve different purposes, checking both is the standard practice.
10.2 Why Is javac Not Found?
- The JDK is not installed
- PATH is not set correctly
In most cases, it’s one of these two reasons.
10.3 I Installed Java, but an Old Version Is Still Displayed
This usually means a different Java has higher priority in PATH.
Check the actual binary with where java (Windows) or which java (macOS/Linux).
10.4 Can I Safely Use Multiple Java Versions?
Yes, you can.
However, it’s crucial to always know which Java is currently in use.
10.5 Which Java Version Should I Use?
If there’s no special requirement, choosing an LTS (Long-Term Support) release is the safest option.
If your project specifies a version, always prioritize that requirement.

