Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check the jdk version used to compile a .class file [duplicate]

Tags:

java

Possible Duplicate:
Tool to read and display Java .class versions

I'm trying to debug a

"Bad version number in .class file'

error in java, is there a way for me to check which version the .class files are?

I'm using JRE1.5.0_6, but my JDK is version 1.6.0_13.

I'm compiling with compatibility mode set to 1.5 in eclipse which I thought would work...

like image 591
Charles Ma Avatar asked Jul 08 '09 04:07

Charles Ma


People also ask

How can I tell what version of Java a compiled class is?

In Java, we can use javap -verbose className to print out the class information. D:\projects>javap -verbose Test Classfile /D:/projects/Test. class Last modified 16 Apr 2019; size 413 bytes MD5 checksum 8679313dc0728e291898ad34656241cb Compiled from "Test.

What is the JDK command to compile a class?

Description. The javac command reads source files that contain module, package and type declarations written in the Java programming language, and compiles them into class files that run on the Java Virtual Machine. The javac command can also process annotations in Java source files and classes.


1 Answers

You're looking for this on the command line (for a class called MyClass):

On Unix/Linux:

javap -verbose MyClass | grep "major" 

On Windows:

javap -verbose MyClass | findstr "major" 

You want the major version from the results. Here are some example values:

  • Java 1.2 uses major version 46
  • Java 1.3 uses major version 47
  • Java 1.4 uses major version 48
  • Java 5 uses major version 49
  • Java 6 uses major version 50
  • Java 7 uses major version 51
  • Java 8 uses major version 52
  • Java 9 uses major version 53
  • Java 10 uses major version 54
  • Java 11 uses major version 55
like image 116
John Calsbeek Avatar answered Sep 23 '22 10:09

John Calsbeek