How to check Java version command line?
Jul 13, 2025 am 01:49 AMTo check the Java version, 1. Use java -version to view the runtime version; 2. Use javac -version to confirm the JDK installation and version; 3. Use which java or for %i in (java.exe) do @echo. %~$PATH:i to find the installation path; 4. When multiple versions coexist, you can change JAVA_HOME or use SDKMAN! or Jabba to switch versions.
Checking Java versions on the command line is a basic but often required operation, especially when developing, deploying, or debugging Java applications. You only need a simple command to quickly view the Java version installed on the current system.

Use java -version
command
This is the most direct and common method. Open your command line tool (such as Windows CMD, PowerShell, or macOS/Linux terminal) and enter the following command:
java -version
After execution, you will see an output similar to the following:

openjdk version "17.0.8" 2023-07-18 OpenJDK Runtime Environment (build 17.0.8 7) OpenJDK 64-Bit Server VM (build 17.0.8 7, mixed mode)
This indicates that the Java version in the current running environment is 17.0.8. Note that this command displays the runtime environment version, that is, the information of the JRE.
If you need more complete development environment information (including JDK), you can continue to see the next section.

Check JDK version using javac -version
If you want to confirm whether the JDK (Java Development Kit) is installed and its version, you can use:
javac -version
The output is usually as follows:
javac 17.0.8
This command can help you determine whether you have the ability to compile Java programs. If the prompt command is not found, it may be that only JRE is installed but not JDK is installed.
View Java installation path (optional)
Sometimes you know that Java is installed, but you are not sure where to install it. You can use the following command to find the Java installation path:
- On Windows :
for %i in (java.exe) do @echo. %~$PATH:i
- On macOS/Linux :
which java
Or more detailed:
/usr/libexec/java_home
These commands can help you locate the location of Java executables and also help configure environment variables.
How to switch when multiple versions coexist
Some developers will install multiple Java versions (such as Java 8 and Java 17) on the same machine. At this time, you can switch the default version by setting environment variables or using the version management tool.
Common practices include:
- Manually modify the
JAVA_HOME
environment variable to point to different versions - Use tools such as SDKMAN! (for macOS/Linux)
- You can use tools like Jabba in Windows
Basically that's it. The operation is not complicated, but it is very practical in daily development.
The above is the detailed content of How to check Java version command line?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Many friends who use win10 system have encountered this problem when playing games or installing the system. The application cannot be started because the parallel configuration of the application is incorrect. For more information, see the application event log, or use the command line sxstrace.exe tool. This may be because the operating system does not have corresponding permissions. Let’s take a look at the specific tutorial below. Tutorial on using the command line sxstrace.exe tool 1. This problem usually occurs when installing programs and games. The prompt is: The application cannot be started because the parallel configuration of the application is incorrect. For more information, see the application event log, or use the command line sxstrace.exe tool. 2. Start →

For those unfamiliar, Low Power Mode reduces your Mac's energy usage, potentially extending battery life at the expense of performance temporarily, but it's handled well enough that for most users, they won't notice to any particular degradation. This is a very useful mode if you're a Mac laptop user trying to get the most battery life possible from your MacBook Pro or Air. Enable Mac Low Power Mode from the Command Line From the Terminal, type the following command string on any Mac laptop: sudo pmset -a lowpowermode 1 Press Enter as sudo requires and enter the administrator password to authenticate.

This article details the steps to upgrade Ubuntu 20.04 to 22.04. For users using Ubuntu 20.04, they have missed the new features and advantages brought by version 22.04. In order to get a better experience and security, it is recommended to upgrade to a newer Ubuntu version in time. Ubuntu22.04 is codenamed "Jamie Jellyfish", let's explore how to get the latest LTS version! How to upgrade Ubuntu 20.04 to 22.04 via the command line Mastering the command line will give you an advantage. While it is possible to update Ubuntu via the GUI, our focus will be via the command line. First, let’s check the currently running version of Ubuntu using the following command: $

Start the journey of Django project: start from the command line and create your first Django project. Django is a powerful and flexible web application framework. It is based on Python and provides many tools and functions needed to develop web applications. This article will lead you to create your first Django project starting from the command line. Before starting, make sure you have Python and Django installed. Step 1: Create the project directory First, open the command line window and create a new directory

In Python, parameters can be passed to scripts via the command line. These parameters can be used inside scripts to perform different actions based on different inputs. Detailed explanation of Python command line parameters: 1. Positional parameters: parameters passed to the script in order on the command line. They can be accessed through position inside the script; 2. Command line options: parameters starting with - or -, usually Used to specify specific options or flags for the script; 3. Pass parameter values: Pass parameter values ??through the command line.

How to perform log aggregation and statistics through Linux command line tools? Logging is a very important task when managing and maintaining Linux systems. Through logs, you can view system operation, troubleshoot problems, and conduct performance analysis. For large-scale systems, the number of logs is often very large. How to efficiently aggregate and count logs has become a challenge faced by operation and maintenance personnel. In Linux systems, we can use command line tools for log aggregation and statistics. The following will introduce several commonly used command lines

When using Maven to build a Java project, you often encounter situations where you need to set the Java version. Correctly setting the Java version can not only ensure that the project runs normally in different environments, but also avoid some compatibility issues and improve the stability and maintainability of the project. This article will introduce the best practices and recommended methods for setting Java versions in Maven, and provide specific code examples for reference. 1. Set the Java version in the pom.xml file. In the pom.xml file of the Maven project, you can

Solution to the problem that javac is not an internal or external command and is not an operable program: 1. First download the latest version of JDK from the official website and install it; 2. Configure the system environment variables and add the jdk installation path to the path; 3. Enter the computer command Run the interface, enter "java -v" and the version number will appear.
