Forums Register Login

How to find the version of given class file?

+Pie Number of slices to send: Send
Hi Friends,

I am having a classfile and i would like to findout the version of javac that compiled this class. How can i do that.

Thanks in advance,

regards,
dinesh Venkatesan.
+Pie Number of slices to send: Send
You can't. You can only determine for which version of the JVM the code was compiled. Generally, javac will generate bytecode for the JVM version that it shipped with (i.e., javac in Java 5 will create Java 5 bytecode), but that can be changed using the -source and -target switches.

Bytes 5 through 8 of a class file contain the minor and major class file version (i.e., the one specified by the "-target" switch). Some more detail can be found here.
+Pie Number of slices to send: Send
Here's a small program that shows the class file version number. However, the class file version number is not the same as the JDK version number with which it is compiled.

For Java 1.4, you'll get 48.0, for Java 5 you'll get 49.0 and for Java 6 you'll get 50.0. But as Ulf already said, you can also create version 48.0 and 49.0 files with the compiler in JDK 6, if you use the -source and -target switches.

[ August 16, 2007: Message edited by: Jesper Young ]
+Pie Number of slices to send: Send
Hi Ulf,

Thanks much for the help. But could you tell me how to get the information that represents the major version in the file. Should I go for BCEL?

regards,
dinesh V
+Pie Number of slices to send: Send
What information are you looking for that Jesper's code doesn't provide?

BCEL can give you this information, but that would seem to be rather more effort than the above solution.
+Pie Number of slices to send: Send
Yes Ulf, Jasper's code gave me the info i wanted.
Thanks Jasper
It's exactly the same and completely different as this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1041 times.
Similar Threads
Read class of Major Version 48 and more
Re-building the class files in JDK 1.6
which jdk was used to compile this class?
version of join() method
Major Version and Minor version
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:13:43.