How to check Java version on compiled class
Recently working with Java and encountered some issue regarding java version when I run my java program.
1) First start your command prompt.
2) For those who don't have the javap class path matched, navigate into bin folder inside your Java folder.
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;
Its said that the version of my program is incompatible and it is expecting some version else.
After some searching, here is one of my finding on how to check the java version for a compiled class.
1) First start your command prompt.
2) For those who don't have the javap class path matched, navigate into bin folder inside your Java folder.
The command is as simple as below:
javap -verbose MyClass
(MyClass is my class file name)
This might output a junk of coding which is not required in this case.
The java class can be determined in the early stage.
So output everything into a file,
javap -verbose MyClass > myclass.log
And now open the the myclass.log and you can see the following at the start.
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;
The highlighted red color is the point to determine the java version for this MyClass.class.
It is mapped in the below table:
major minor Java platform version 45 3 1.0 45 3 1.1 46 0 1.2 47 0 1.3 48 0 1.4 49 0 1.5 50 0 1.6
This example mean that the class is compiled in Java version 1.6.
Hope this help in your finding.
Good luck and Happy Coding!!!
Comments
Post a Comment