Whether you're debugging an issue, ensuring compatibility with libraries, or preparing to upgrade to a newer version, knowing the version of Java installed on the system is a fundamental skill. Java version affects the functionalities available, so it's crucial to verify it before starting a new project or running existing code. This tutorial explains how to check Java version.
1. 'version' option
The fastest way to check the Java version from the command line is by using the version
option:
java -version
The result will look something like this:
openjdk version "21.0.5" 2024-10-15
OpenJDK Runtime Environment (build 21.0.5+11-Ubuntu-1ubuntu124.04)
OpenJDK 64-Bit Server VM (build 21.0.5+11-Ubuntu-1ubuntu124.04, mixed mode, sharing)
2. 'java.version' system property
If you're writing a program and need to check the Java version dynamically, you can get it using the java.version
system property:
public class Main
{
public static void main(String[] args)
{
String version = System.getProperty("java.version");
System.out.println(version);
}
}
Leave a Comment
Cancel reply