This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes find javac version that compiled my class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "find javac version that compiled my class" Watch "find javac version that compiled my class" New topic
Author

find javac version that compiled my class

Eric Krieger
Greenhorn

Joined: Jul 13, 2008
Posts: 1
I can use System.getProperty( "java.version" ) to find and display the JRE under which my program is running, but is there a straightforward way [I am a java newbie] to find the JDK version of 'javac' that was used to compile my .java file ? I am using Sun java exclusively.

-Eric
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41052
    
  43
No, that's not possible. What is possible, however is to find out for which version of Java the code was compiled; in other words, which JRE version is needed to run it. Frequently that's sufficient information.

If it is in your case, have a look at the bytes 6 and 7 (counting from 0) in the class file. They encode the targeted JRE version. See the table in this Wikipedia entry for details of what the numbers mean.

You can change the targeted JRE version during compilation by using javac's "-source" and "-target" switches.


Ping & DNS - my free Android networking tools app
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37902
    
  22
. . . and welcome to JavaRanch, Eric
Bill Cruise
Ranch Hand

Joined: Jun 01, 2007
Posts: 148
You can use javap -verbose MyClass to find the JVM version information.

Example output:

Compiled from "MyClass.java"
public class MyClass extends java.lang.Object
SourceFile: "MyClass.java"
minor version: 0
major version: 50

Constant pool:
const #1 = class #2; // MyClass
const #2 = Asciz MyClass;
const #3 = class #4; // java/lang/Object
const #4 = Asciz java/lang/Object;
.
.

Use this table to decode the major/minor version:

[ July 14, 2008: Message edited by: Bill Cruise ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41052
    
  43
You can use javap -verbose MyClass to find the JVM version information.

Neat!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: find javac version that compiled my class
 
Similar Threads
Why this EL code part is not working
Java Compiler version
errors generated when running Ant build file in Eclipse
Installing JDK in Windows 7
Eclips error