aspose file tools*
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
Author

Class files related

Rakesh Ravindra
Greenhorn

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.

thanks


"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
Marshal

Joined: Mar 22, 2005
Posts: 42634
    
  65
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).


Ping & DNS - my free Android networking tools app
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 ]

42
Vinay Raj
Ranch Hand

Joined: Jun 19, 2006
Posts: 81
You will find the following thread useful.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class files related