Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

It's easy to check the JDK version that a .class file has been compiled with using the javap tool. Simply run something like this...
 Terminal
javap -v MyClass | grep major


That will produce output like this...
 Terminal
major version: 51


Even though I primarily code in Java, I never remember the class version names and their equivalent JDK versions. So instead of looking it up I added this handy function to my Bash ~/.profile file to tell me the JDK version for a .class file...
 Bash ~/.profile function
jversion() {
case $(javap -v $1|grep major|awk '{print $3}') in
46)
echo 'Java 1.2'
;;
47)
echo 'Java 1.3'
;;
48)
echo 'Java 1.4'
;;
49)
echo 'Java 5'
;;
50)
echo 'Java 6'
;;
51)
echo 'Java 7'
;;
52)
echo 'Java 8'
;;
53)
echo 'Java 9'
;;
*)
echo 'Unrecognised Java version'
esac
}




Using it is simple, simply do this:
 Terminal
jversion MyClass


The output is a little bit more friendly than what javap produces, for example:
 Terminal
Java 8


-i

A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.