Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to find out from *.class file with which Java version 1.6 or 1.5 it was compiled?

8 views
Skip to first unread message

Gianni Galore

unread,
Aug 4, 2010, 10:21:15 AM8/4/10
to
Assume I got a *.class file.

Is there a way to find out with which java version (e.g. 1.5upd14 or v1.6.upd20) this *.class
file was previously compiled?

Gianni

Lew

unread,
Aug 4, 2010, 11:33:39 AM8/4/10
to

<http://java.sun.com/docs/books/jvms/second_edition/html/
ClassFile.doc.html>
The first four bytes of the class file comprise the magic number
0xCAFEBABE (unsigned int).
The next two bytes comprise the minor version number of the class file
format (unsigned short).
The next two bytes comprise the major version number of the class file
format (unsigned short).

The major and minor versions tell you what version of Java can run the
class file, but not necessarily which version produced it. I don't
know of any way to get at the Java version that compiled it, but you
can live without that information anyway.

Class file formats do not change between minor Java version updates,
and not even necessarily between major Java version updates.

You should know that Java 5u14 and 6u20 lack certain critical bug and
security fixes and you should upgrade to the latest available versions
of those products, updates 22 and 21, respectively. (Java 5 has been
frozen for public use at update 22, having reached its end-of-service-
life on November 3, 2009, though paying customers can get more recent
updates. Yes, that's right, Java 5 has been officially obsolete for
nine months, a fact that your customers who are only just now
upgrading from their obsolete 8 1/2-year-old version to the obsolete
nearly-6-year-old version really should find out.)

You can find which major class file versions correspond to which Java
versions at
<http://mindprod.com/jgloss/javaclassformat.html>

--
Lew

Lew

unread,
Aug 4, 2010, 12:27:04 PM8/4/10
to

Cross-posting is not terrible, but usually it's enough to post your
query in one newsgroup or another without cross-posting. That's
especially true for comp.lang.java.programmer and comp.lang.java.help
which have substantially the same readership.

You did do the cross-post exactly correctly, mind you. No complaints
there. It just probably didn't do very much to help you.

--
Lew

Joshua Cranmer

unread,
Aug 4, 2010, 7:53:20 PM8/4/10
to

If you have the file utility on your computer, file knows about Java
version numbers:

$ file Review.class
Review.class: compiled Java class data, version 50.0 (Java 1.6)

If you don't, here is a brief overview of the class header format:

$ hd Review.class
00000000 ca fe ba be 00 00 00 32 00 78 0a 00 28 00 47 09
^^^^^^^^^^^ ^^^^^ ^^^^^
magic minor major

The magic number is always 0xCAFEBABE: this is what tells the JVM that
the following file is a Java class file. The major file number is a
16-bit short. Version 50 corresponds to 6, 49 to 5, 48 to 1.4, 47 1.3,
46 1.2, and 45 1.1 or lower. The minor file number is only used in
practice for 1.0 versus 1.1 detection (I believe 1.1 is actually 45.3,
but don't quote me on that).

Any more precise versioning is not reified into the class files; in
general, it should not matter.
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth

Arne Vajhøj

unread,
Aug 4, 2010, 10:46:17 PM8/4/10
to

You can see what Java version (1.4/1.5/1.6) is is compiled for.

http://en.wikipedia.org/wiki/Java_class_file documents the format.

Note that:
- compiled for != compiled on
- no changes by updates

Arne

Kevin McMurtrie

unread,
Aug 4, 2010, 10:57:38 PM8/4/10
to
In article <4c59775a$0$6889$9b4e...@newsspool2.arcor-online.net>,
gg...@osgitest.org (Gianni Galore) wrote:

Class files have a version number in them but it correlates
to the bytecode version rather than the compiler's. Luckily
1.5 and 1.6 have different bytecode versions.

javap -verbose <classname>

1.5 has this:
minor version: 0
major version: 49

1.6 has this:
minor version: 0
major version: 50

Or read this:
http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html

The header is 0xcafebabe followed by a 16 bit minor version and
a 16 bit major version.

xxd -p -s 4 -l 4 -c 2 <classfilename>

1.5
0000
0031

1.6:
0000
0032
--
I won't see Google Groups replies because I must filter them as spam

Tom Anderson

unread,
Aug 5, 2010, 10:17:18 AM8/5/10
to

There's a version number in the class file. If you're on a reasonably
modern unix, the 'file' command will identify class files and give their
version number. If not, javap -verbose prints it at the top of its output.

You can then look the version number up in a table to find the java
version that compiled it:

http://mindprod.com/jgloss/javaclassformat.html

The resolution is not as high as you might like - it won't tell you which
patch or update version the compiler was from. I don't think there's any
way to find that from the class file, BICBW.

tom

--
It's Brains you want!

Roedy Green

unread,
Aug 6, 2010, 7:00:37 PM8/6/10
to
On Thu, 5 Aug 2010 15:17:18 +0100, Tom Anderson <tw...@urchin.earth.li>
wrote, quoted or indirectly quoted someone who said :

>You can then look the version number up in a table to find the java
>version that compiled it:
>
>http://mindprod.com/jgloss/javaclassformat.html

there is also a utility to make sure all the class files in a jar fit
in a desired range of JDK versions. See
http://mindprod.com/products1.html#JARCHECK
You can cannibalise the Java source.
--
Roedy Green Canadian Mind Products
http://mindprod.com

You encapsulate not just to save typing, but more importantly, to make it easy and safe to change the code later, since you then need change the logic in only one place. Without it, you might fail to change the logic in all the places it occurs.

ClassCastException

unread,
Aug 16, 2010, 1:17:40 AM8/16/10
to

That's absolutely fascinating, but it's also completely irrelevant as a
response to "Is there a way to find out with which java version (e.g.

1.5upd14 or v1.6.upd20) this *.class file was previously compiled?"

HTH.

Lew

unread,
Aug 16, 2010, 8:35:47 AM8/16/10
to
Lew wrote:
>> You did do the cross-post exactly correctly, mind you. No complaints
>> there. It just probably didn't do very much to help you.

ClassCastException wrote:
> That's absolutely fascinating, but it's also completely irrelevant as a
> response to "Is there a way to find out with which java version (e.g.
> 1.5upd14 or v1.6.upd20) this *.class file was previously compiled?"

Wrong.

--
Lew

ClassCastException

unread,
Aug 16, 2010, 10:29:27 PM8/16/10
to

No, not wrong. Your comments about cross-posting correctly do, indeed,
have fuck-all to do with determining the version of Java used to compile
an in-hand .class file.

Lew

unread,
Aug 16, 2010, 10:40:27 PM8/16/10
to
ClassCastException wrote:
>>> That's absolutely fascinating, but it's also completely irrelevant as a
>>> response to "Is there a way to find out with which java version (e.g.
>>> 1.5upd14 or v1.6.upd20) this *.class file was previously compiled?"

Lew wrote:
>> Wrong.

ClassCastException wrote:
> No, not wrong. Your comments about cross-posting correctly do, indeed,
> have fuck-all to do with determining the version of Java used to compile
> an in-hand .class file.

You are mistaken.

--
Lew

ClassCastException

unread,
Aug 16, 2010, 10:54:01 PM8/16/10
to

Simply repeating a claim after it's been disproved, without even
attempting to provide some actual evidence and some actual arguments to
support it, does not accomplish much.

It does, mind you, make you look like a small, petulant child, FWIW.

Lew

unread,
Aug 16, 2010, 10:59:03 PM8/16/10
to
ClassCastException wrote:
>>> No, not wrong. Your comments about cross-posting correctly do, indeed,
>>> have fuck-all to do with determining the version of Java used to
>>> compile an in-hand .class file.


Your own post is similarly relevant as mine. Both of us sought to improve the
user's experience by pointing out some metainformation about the communication
channel. Neither of us answered the query directly, true, but both of us
wanted to increase the reach and power of the query, thus empowering it. By
pointing out with positive reinforcement that the OP had used cross-posting
correctly, albeit perhaps not usefully, I was providing meta-information that
will improve his results in all communications through the news group. By
pointing out what you perceive as off-purpose communication, you clearly hope
to reduce the signal-to-noise ratio thus helping relevant information stand
out more clearly. Bully for you.

--
Lew

ClassCastException

unread,
Aug 16, 2010, 11:07:13 PM8/16/10
to
On Mon, 16 Aug 2010 22:59:03 -0400, Lew wrote:

> ClassCastException wrote:
>>>> No, not wrong. Your comments about cross-posting correctly do,
>>>> indeed, have fuck-all to do with determining the version of Java used
>>>> to compile an in-hand .class file.
>
> Your own post is similarly relevant as mine.

My post was relevant to the body text of the post it was directly
replying to. Yours was not.

> Both of us sought to improve the user's experience by pointing out some
> metainformation about the communication channel.

Q: How do I know which Java version compiled this class file?
A: something about crossposting

Yeah, real "improvement" to the user experience there. If the user's an
avid collector of non sequiturs, anyway.

> Neither of us answered the query directly, true

You didn't answer it even indirectly. Your post said nothing at all about
versioning of class files. And whereas mine also didn't, mine was also
NOT a direct followup to the OP.

> By pointing out with positive reinforcement that the OP had used cross-
> posting correctly, albeit perhaps not usefully, I was providing meta-
> information that will improve his results in all communications through
> the news group.

I think it would have improved his results a lot more had your initial
followup contained an actual answer to his question.

> By pointing out what you perceive as off-purpose communication, you
> clearly hope to reduce the signal-to-noise ratio thus helping relevant
> information stand out more clearly. Bully for you.

ITYM increase the signal-to-noise ratio.

Lew

unread,
Aug 16, 2010, 11:17:56 PM8/16/10
to
ClassCastException wrote:
> I think it would have improved his results a lot more had your initial
> followup contained an actual answer to his question.

Have you been reading this thread? (That's a rhetorical question.) I not
only answered his question first, I was first to answer his question. My
comments about cross-posting were sent nearly an hour later. Here's what I said,
> <http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html>


> The first four bytes of the class file comprise the magic number
> 0xCAFEBABE (unsigned int).
> The next two bytes comprise the minor version number of the class file
> format (unsigned short).
> The next two bytes comprise the major version number of the class file
> format (unsigned short).
>
> The major and minor versions tell you what version of Java can run the
> class file, but not necessarily which version produced it. I don't
> know of any way to get at the Java version that compiled it, but you
> can live without that information anyway.
>
> Class file formats do not change between minor Java version updates,
> and not even necessarily between major Java version updates.
>
> You should know that Java 5u14 and 6u20 lack certain critical bug and
> security fixes and you should upgrade to the latest available versions
> of those products, updates 22 and 21, respectively. (Java 5 has been
> frozen for public use at update 22, having reached its end-of-service-
> life on November 3, 2009, though paying customers can get more recent
> updates. Yes, that's right, Java 5 has been officially obsolete for
> nine months, a fact that your customers who are only just now
> upgrading from their obsolete 8 1/2-year-old version to the obsolete
> nearly-6-year-old version really should find out.)
>
> You can find which major class file versions correspond to which Java
> versions at
> <http://mindprod.com/jgloss/javaclassformat.html>

Note that I answered in detail and provided links for further information.

The mindprod site cited is a good summary.

--
Lew
I accept your apology.

ClassCastException

unread,
Aug 17, 2010, 3:29:16 AM8/17/10
to
On Mon, 16 Aug 2010 23:17:56 -0400, Lew wrote:

> ClassCastException wrote:
>> I think it would have improved his results a lot more had your initial
>> followup contained an actual answer to his question.
>
> Have you been reading this thread?

Yes -- every post of it.

> I not only answered his question first, I was first to answer his
> question. My comments about cross-posting were sent nearly an hour
> later.

That's simply not true. This thread consists of:

<4c59775a$0$6889$9b4e...@newsspool2.arcor-online.net> -- the OP
<961ea200-1357-4209...@w30g2000yqw.googlegroups.com> --
your comments about crossposting
<i4ahlk$2gf$3...@news.eternal-september.org> -- me
<i4bbak$msd$1...@news.albasani.net> -- your reply to me
<i4cs67$j58$5...@news.eternal-september.org> -- back and forth...
<i4csq8$vb3$2...@news.albasani.net>
<i4ctk9$j58$1...@news.eternal-september.org>
<i4ctvr$m4$1...@news.albasani.net>
<i4cud0$j58$1...@news.eternal-september.org>
<i4cv0i$2l9$1...@news.albasani.net> -- your latest post
and <h0b7661j3mauhi9u8...@4ax.com> -- Roedy attempting to
answer the question

That's it. Every post by you is either the cross-posting comment or a
descendant of that and none of them answer the OP's question. Eternal-
September currently has 11 posts of this thread -- about to become 12.

If you did post anything else to this thread, it failed to propagate.

I notice you make most of your posts through Albasani, but your initial
cross-post comment was posted via Google Groups. I suspect you'd resort
to Google Groups only if something was wrong with Albasani at the time.
Perhaps you attempted to post an actual answer to the OP's problem via
Albasani just as it developed technical difficulties, and Albasani
claimed the post was successful and perhaps did spool it locally but
failed to propagate it due to the precise timing of the fault?

Lew

unread,
Aug 17, 2010, 9:19:44 AM8/17/10
to
ClassCastException wrote:
>>> I think it would have improved his results a lot more had your initial
>>> followup contained an actual answer to his question.

Lew wrote:
>> Have you been reading this thread? (That's a rhetorical question.)

ClassCastException wrote:
> Yes -- every post of it.

Apparently not, as your responses /infra/ show. Also, I pointed out that the
question was rhetorical. How interesting that you chose to answer anyway.

Lew wrote:
>> I not only answered his question first, I was first to answer his
>> question. My comments about cross-posting were sent nearly an hour
>> later.

ClassCastException wrote:
> That's simply not true. This thread consists of:

It simply is true.

You're just being fractious to be a troll.

> That's it. Every post by you is either the cross-posting comment or a

Wrong. I quoted the post in its entirety. I got that quote from Usenet, from
the post I put up on 8/4 at 15:33 Z. Did you read my quote? Your argument is
based on false premises. I conclude that you are just being argumentative.

> descendant of that and none of them answer the OP's question. Eternal-

Except my first one, which for some reason you missed or suppressed.

> September currently has 11 posts of this thread -- about to become 12.

I count 17 about to become 18 with this here post right here. You should get
your ISP straightened out.

Your count is waaaaay off. ASre you sure you

> If you did post anything else to this thread, it failed to propagate.

How generous of you to allow, but it propagated just fine.
<http://groups.google.com/group/comp.lang.java.help/browse_thread/thread/c8afff58b21f093c#>
shows it, for example.

> I notice you make most of your posts through Albasani, but your initial
> cross-post comment was posted via Google Groups. I suspect you'd resort
> to Google Groups only if something was wrong with Albasani at the time.
> Perhaps you attempted to post an actual answer to the OP's problem via
> Albasani just as it developed technical difficulties, and Albasani
> claimed the post was successful and perhaps did spool it locally but
> failed to propagate it due to the precise timing of the fault?

I still see my original post nearly two weeks later, both from Albasani and
from GG (the latter linked from this post).

--
Lew
Last chance for me to accept your apology.

Lars Enderin

unread,
Aug 17, 2010, 12:35:03 PM8/17/10
to
For the record:
I see only 12 posts in this thread (in comp.lang.java.programmer). I
don't subscribe to comp.lang.java.help, and I don't see your first reply
to the OP. My ISP is albasani, and my news reader is Thunderbird 3.0.6
(Linux X86_64). It shows links to the rest of the thread. The links are
numbered 1-11. Number 2 is
<961ea200-1357-4209...@w30g2000yqw.googlegroups.com>.


Lew

unread,
Aug 17, 2010, 2:58:02 PM8/17/10
to
Lew wrote:
>> I still see my original post nearly two weeks later, both from Albasani
>> and from GG (the latter linked from this post).
>

Lars Enderin wrote:
> For the record:
> I see only 12 posts in this thread (in comp.lang.java.programmer). I
> don't subscribe to comp.lang.java.help, and I don't see your first reply
> to the OP.
>

Then you are deliberately counting the wrong group.

Given that the OP posted with a followup to clj.help, that would be
where you would expect replies to appear and whence you would get the
authoritative and accurate count of posts. ClassCastException was
being just a tad disingenuous in discounting my reply simply because
it showed up exactly where the OP wanted.

This does illustrate the relevance of my comment about cross-posting.
People don't even know what was said in the conversation because of
it, for pity's sake.

--
Lew

ClassCastException

unread,
Aug 17, 2010, 10:50:04 PM8/17/10
to
On Tue, 17 Aug 2010 09:19:44 -0400, Lew wrote:

> ClassCastException wrote:
>>>> I think it would have improved his results a lot more had your
>>>> initial followup contained an actual answer to his question.
>
> Lew wrote:
>>> Have you been reading this thread? (That's a rhetorical question.)
>
> ClassCastException wrote:
>> Yes -- every post of it.
>
> Apparently not, as your responses /infra/ show.

Apparently yes, since I just enumerated every single post to this thread
that Eternal-September has in its spool.

> Also, I pointed out that the question was rhetorical. How interesting
> that you chose to answer anyway.

Because you were drawing a wrong conclusion that needed to be corrected.

> Lew wrote:
>>> I not only answered his question first, I was first to answer his
>>> question. My comments about cross-posting were sent nearly an hour
>>> later.
>
> ClassCastException wrote:
>> That's simply not true. This thread consists of:
>
> It simply is true.

It simply isn't. I listed off, citing message-IDs, every single post in
this thread at that time, and not one of them was by you and answering
the OP's question.

I don't know why you persist in claiming that there's an additional post
to this thread, given how easy it is to see that there is not.

> You're just being fractious to be a troll.

Incorrect.

>> That's it. Every post by you is either the cross-posting comment or a
>
> Wrong.

No, not wrong.

> I quoted the post in its entirety.

What you "quoted" did not, apparently, actually exist in this thread
until you "quoted" it.

> I got that quote from Usenet, from the post I put up on 8/4 at 15:33
> Z.

You got that quote directly out of your butt, from what I can tell.
Certanly there is no post in this thread by you dated 8/4 15:33 Z. The
first post to this thread is by Gianni Galore dated 8/4 14:21 Z and the
second post to this thread is by you dated 8/4 16:27 Z. There's nothing
in between.

> Did you read my quote?

Yes, not that it mattered since the post you were "quoting" doesn't exist.

> Your argument is based on false premises.

No, yours is -- yours is predicated on the assumption that we'll just
believe in your phantom 15:33 post even when it doesn't actually appear
in this thread and all we have to support the notion that you even wrote
and *attempted* to send such a post is your self-serving word for it.

> I conclude that you are just being argumentative.

That's funny, because from where I'm sitting it looks like *you* are just
being argumentative.

>> descendant of that and none of them answer the OP's question. Eternal-
>
> Except my first one, which for some reason you missed or suppressed.

I did neither. It does not exist, or, at the very least, Eternal-
September does not have it.

>> September currently has 11 posts of this thread -- about to become 12.
>
> I count 17 about to become 18 with this here post right here.

Incorrect. At that time it was 12 about to become 13.

> You should get your ISP straightened out.

I'm not using my ISP's news server. I'm using Eternal-September. It now
has 15 posts in this thread, about to become 16.

> Your count is waaaaay off.

No, *your* count is waaaaay off.

> ASre you sure you

What?

>> If you did post anything else to this thread, it failed to propagate.
>
> How generous of you to allow, but it propagated just fine.

Obviously not, or I'd have read it.

If, that is, you even posted it at all, for which (again) we have only
your word.

ClassCastException

unread,
Aug 17, 2010, 10:55:38 PM8/17/10
to
On Tue, 17 Aug 2010 11:58:02 -0700, Lew wrote:

> Lew wrote:
>>> I still see my original post nearly two weeks later, both from
>>> Albasani and from GG (the latter linked from this post).
>>
>>
> Lars Enderin wrote:
>> For the record:
>> I see only 12 posts in this thread (in comp.lang.java.programmer). I
>> don't subscribe to comp.lang.java.help, and I don't see your first
>> reply to the OP.
>>
>>
> Then you are deliberately counting the wrong group.

He -- and I -- are deliberately counting the group we are actually
reading and not some other group.

> Given that the OP posted with a followup to clj.help,

He did? That's news to me. But then, it's not visible when just casually
reading the post, and since I didn't know how to answer the OP's
question, I never hit 'f' while reading it.

> ClassCastException was being just a tad disingenuous in discounting my
> reply simply because it showed up exactly where the OP wanted.

That statement is incorrect in multiple ways. I discounted your reply
because it did not show up at all, at least not that I ever saw. In fact
this is the first you've claimed to have posted it only to cljh and not
to cljp. Since your reply that I did see was posted to both, there was no
logical reason why any hypothetical other post of yours wouldn't also
have been.

> This does illustrate the relevance of my comment about cross-posting.
> People don't even know what was said in the conversation because of it,
> for pity's sake.

Funnily enough, your usual complaint is that *multi*posting will result
in such confusion. Apparently so will crossposting if you drop some
groups from followups, and especially if you do so from *some* followups
and not others. Indeed, you made statements about your past posts that
are apparently true if read in comp.lang.java.help and false if read in
comp.lang.java.programmer! The statements in question should either have
been rephrased or posted only to cljh to avoid their being untrue in some
of the contexts in which they'd be read.

Lew

unread,
Aug 18, 2010, 7:28:22 PM8/18/10
to
On 08/17/2010 10:50 PM, ClassCastException wrote:
>>> If you did post anything else to this thread, it failed to propagate.

Lew wrote:
>> How generous of you to allow, but it propagated just fine.

ClassCastException wrote:
> Obviously not, or I'd have read it.
>
> If, that is, you even posted it at all, for which (again) we have only
> your word.

Wrong. You deliberately clipped the line from my post just after "it
propagated just fine":

which shows that you are a troll and a bounder.

--
Lew

Alan Gutierrez

unread,
Aug 18, 2010, 7:54:01 PM8/18/10
to
Lew wrote:

> which shows that you are a troll and a bounder.

What's a bounder?

--
Alan Gutierrez - al...@blogometer.com - http://twitter.com/bigeasy

Lew

unread,
Aug 18, 2010, 8:18:24 PM8/18/10
to
Lew wrote:
>> which shows that you are a troll and a bounder.

Alan Gutierrez wrote:
> What's a bounder?

http://en.wiktionary.org/wiki/bounder
http://www.merriam-webster.com/dictionary/bounder
http://dictionary.reference.com/browse/bounder

or choose your own favorite dictionary.

--
Lew

Alan Gutierrez

unread,
Aug 18, 2010, 9:26:32 PM8/18/10
to

How embarrassing. I searched for "bounder usenet" thinking it was part
of online forum/moderation nomenclature. Who would have thought to look
in the dictionary?

ClassCastException

unread,
Aug 18, 2010, 11:05:04 PM8/18/10
to
On Wed, 18 Aug 2010 19:28:22 -0400, Lew wrote:

> On 08/17/2010 10:50 PM, ClassCastException wrote:
>>>> If you did post anything else to this thread, it failed to propagate.
>
> Lew wrote:
>>> How generous of you to allow, but it propagated just fine.
>
> ClassCastException wrote:
>> Obviously not, or I'd have read it.
>>
>> If, that is, you even posted it at all, for which (again) we have only
>> your word.
>
> Wrong.

No, not wrong.

> You deliberately clipped the line from my post just after "it
> propagated just fine":
>
>> <http://groups.google.com/group/comp.lang.java.help/browse_thread/
thread/c8afff58b21f093c#>

I clipped that line because it's irrelevant. The topic of our discussion
was THIS thread, in comp.lang.java.PROGRAMMER. You linked to a thread in
comp.lang.java.HELP, a group I don't even read. Obviously anything you
posted (solely) there I won't have seen, nor will lots of other people.

> which shows that you are a troll and a bounder.

I'm not the one who has resorted to namecalling and similarly childish
antics in this dispute.

David

unread,
Aug 19, 2010, 3:25:01 AM8/19/10
to
On Aug 19, 4:05 am, ClassCastException <zjkg3d9g...@gmail.invalid>
wrote:

What a fascinating thread.

I'm guessing none of you get out much.
Seriously - the sun is shining - get out and try to get laid. It will
really help you...

David A.

ClassCastException

unread,
Aug 19, 2010, 10:49:25 PM8/19/10
to

Speak for yourself. I get some from the missus most nights. Can't vouch
for Lew, though.

0 new messages