File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Class files related Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Class files related" Watch "Class files related" New topic

Class files related

Rakesh Ravindra

Joined: May 02, 2005
Posts: 5
hi ,

i have a question regarding the class files which we get after compiling java files.
From a calss file how can we get to know which jdk was used to compile it?

and will there be any difference between two class files which are obtained from compiling same java file on different systems but using same jdk?

it will be helpful if any one answers these questions.


"Sun is Brown and Grass is Green"
Chetan Raju
Ranch Hand

Joined: Aug 02, 2006
Posts: 109
Regarding your second question, the two class files will be the same even though you are compiling on different systems with same JDK.. remember java is platform independent.

And regarding your first question, even im curious to know as to how to find out which jdk version was used to compile the class had I just had the class file.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
The ultimate reference for this is the JVM specification. The major and minor version numbers are bytes 7/8 and 5/6 of the class file, respectively. This page explains it with a bit more detail. A library like Javassist provides an easily usable API for getting at this information (as do others like ASM and BCEL).
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Of course the classfile version number will not tell you the actual compiler used (say Sun or IBM), just the classfile format that was generated by that compiler (which is all you should have to worry about anyway, unless you suspect there's a bug in that generated bytecode in which case you should contact the person who compiled it and tell them).
[ November 28, 2006: Message edited by: Jeroen T Wenting ]

Vinay Raj
Ranch Hand

Joined: Jun 19, 2006
Posts: 81
You will find the following thread useful.
I agree. Here's the link:
subject: Class files related
It's not a secret anymore!