Identifying what version of javac compiled a class

Is there a way to check a class, to verify what Java version it was compiled under?

I've now replaced my "old-and-busted" JBuilder with the "new hotness" Jbuilder, and I've got it producing classes that actually execute, but I don't trust it yet, and I'd like to verify that it's actually using the compiler I'm telling it to use.

I've currently got one of the classes open in HHD Hex Editor (a little freeware utility I've found very useful in the past), if there's some byte that will tell me where the class came from.

[549 byte] By [hbquikcomjamesla] at [2007-11-26 16:59:57]
# 1

The format can be found here:

http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html

You want to read the major and minor versions. These do not correspond to the actual versions you think about (e.g., 1.4 or 1.5). Here is a table to decode them:

http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.jdt.doc.isv/guide/jdt_api_compile.htm

So, reading offsets 0004-0005 (for minor version) evaluates to zero and reading offsets 0006-0007 (for major version) evaluates to 49. My classfile is JDK 1.5.

- Saish

Saisha at 2007-7-8 23:27:44 > top of Java-index,Java Essentials,Java Programming...
# 2

> I've currently got one of the classes open in HHD Hex

> Editor (a little freeware utility I've found very

> useful in the past), if there's some byte that will

> tell me where the class came from.

Sure. According to the [url=http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html]VM Spec[/url], bytes 4/5 are the major versionumber, and 6/7 are the minor. You might find a compiler marker in the attributes somewhere, but I doubt it; the Sun compilers certainly don't put one there.

Given your recent postings, I'd suggest that you shouldn't be using JBuilder as anything more than an editor. Instead, go to a standardized build process, using a standard JDK distribution (Sun, BEA, IBM, doesn't matter) and a standard build tool (ant, Maven, whatever).

Captain.Obviousa at 2007-7-8 23:27:44 > top of Java-index,Java Essentials,Java Programming...