• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class files related

 
Rakesh Ravindra
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chetan Raju
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will find the following thread useful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic