

There are following ways to find the Java version in Windows: Java provides -version option to find the current Java version.

The first number in Java version represents the major version and the second number represents the release. In this section, we will learn how to check the Java version in Windows using CMD.Ī version string contains a version number optionally followed by pre-release and build information. Some of the applications generally require different version because of compatibility problems. There are different versions of Java is available. $ java -version 2>&1 | grep -q "OpenJDK" & echo "It is OpenJDK." || echo "It is NOT OpenJDK."Īs we can see, it detects OpenJDK correctly.Next → ← prev How to Check Current JDK Version installed in Your System Using CMD? OpenJDK 64-Bit Server VM (build 17.0.3+3, mixed mode) OpenJDK Runtime Environment (build 17.0.3+3) First, let’s run it against an OpenJDK installation: $ java -version Now, let’s test our solution on different Java environments and see if it works as expected. Therefore, we can build a command to check whether the JDK provider is OpenJDK or not: java -version 2>&1 | grep -q "OpenJDK" & echo "It is OpenJDK." || echo "It is NOT OpenJDK."

Only if it succeeds (exit code = 0 ) will CMD2 start. In the example above, CMD1 gets executed first. Let’s understand the operators through a quick example: CMD1 & CMD2 || CMD3 We can make use of the exit code and conditionally concatenate multiple commands using the & and the || operators. $ echo "Java is amazing!" | grep -q 'Java' Otherwise, it returns with the exit code 0: $ echo "Kotlin is amazing!" | grep -q 'Java' But, if the given pattern is not matched, the grep command exits with code 1. When we pass the -q option to the grep command, grep will output nothing.
