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...
javap -v MyClass | grep major

That will produce output like this...
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
echo 'Java 1.2'
echo 'Java 1.3'
echo 'Java 1.4'
echo 'Java 5'
echo 'Java 6'
echo 'Java 7'
echo 'Java 8'
echo 'Java 9'
echo 'Unrecognised Java version'

Using it is simple, simply do this:
jversion MyClass

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


Skip down to comments...
Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...