Java class major/minor version produced by a JDK can be obtained from java
, javac
or javap
commands as follows
java -XshowSettings:properties -version 2>&1 | grep -E -e 'java\.(class\.)?version '
javac -J-XshowSettings:properties -version 2>&1 | grep -E -e 'java\.(class\.)?version '
# testing all 3 commands
for cmd in "java " "javac -J" "javap -J"; do echo "${cmd% *}"; ${cmd}-XshowSettings:properties -version 2>&1 | grep -E -e 'java\.(class\.)?version ' ; done
Result:
java
java.class.version = 61.0
java.version = 17.0.8.1
javac
java.class.version = 55.0
java.version = 11.0.20.1
javap
java.class.version = 55.0
java.version = 11.0.20.1
Note: As in my case :p , a Linux misconfiguration could give different results from java
and javac
showing that both commands belong to different versions. Than can be usually fixed using alternatives
command.