Mostly, after Java installation, we want to know how to get the Java version in the command line interface (Windows/CMD or PowerShell, Linux/Bash, etc.) to check if the Java installation was done correctly.
Furthermore, when we want to develop code according to the Java version, we may want to learn the Java version programmatically.
In this short article, we will learn how to get the Java version either way.
First open the command line interface depending on the Operating system.
For windows; Win+R
then type cmd
or powershel
l, For Linux; you know how to do it 🙂
Then type the following code
java -version
That’s it, You should get something like java version "23" 2024-09-17
There are many Java versions and Java is constantly evolving, so you may want to learn Java version programmatically.
In this case, you can find out the Java version by passing the java.version
parameter to the System.getProperty
method.
System.out.println("Java Version: " + System.getProperty("java.version"));
You can use the value to write code according to the Java version.