aspose file tools*
The moose likes Beginning Java and the fly likes Unexpected java version in class file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unexpected java version in class file" Watch "Unexpected java version in class file" New topic
Author

Unexpected java version in class file

Chris Wang
Ranch Hand

Joined: Jan 13, 2004
Posts: 34
Hi All,

Here is what I did:
1. On my windows XP machine I went to dir--> C:\Program Files\Java\jdk1.4.2_15\bin
2. The java version is 1.4 when I ran java -version. -- correct!
3. I compiled a java file using javac testjava.java without any error.
4. I checked the class file and found the major version number is 2E(46) which is jdk 1.2. -- unexpected!!!

My question is why the major version number inside the class file is NOT 30(48) while using jdk1.4 compiler. Is there anyone can explain why?

Thanks in advance!

Chris
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi Chris,

Did you run the javac command from:

C:\Program Files\Java\jdk1.4.2_15\bin

If not then you might not be using the javac version you think you are. Check that you don't have a separate JAVA_HOME environment variable or the bin directory of another version of Java set in your PATH environment variable.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Chris Wang
Ranch Hand

Joined: Jan 13, 2004
Posts: 34
Hi Martijn,

Thank you for your quick reply!

Yes I did run the javac command under C:\Program Files\Java\jdk1.4.2_15\bin directory, I even made the path empty and my JAVA_HOME is pointing to jdk1.5 actually.

Any idea?

Chris
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

I think it might have to do with class compatibility mode, I _think_ that the default class compatibility is 1.2 in 1.4 mode (but I'm probably clutching a straws here). Have you tried running the class?
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Which java version do you get when you open a command prompt outside "C:\Program Files\Java\jdk1.4.2_15\bin"??


Regards, Rene Larsen
Dropbox Invite
Chris Wang
Ranch Hand

Joined: Jan 13, 2004
Posts: 34
Hi Martijn,

If I open a command console and run java -version I get this:
java version "1.6.0_06"

--I checked I don't have JDK1.6 installed; it's just jre1.6 there, which means that I don't have version 1.6 java compiler.

If I go to C:\Program Files\Java\jdk1.4.2_15\bin and run java -version I get
java version "1.4.2_15"

You might be right! It seems that jdk1.4 compiler is still using class compatibility 1.2 instead of 1.4. I just don't understand why is that.
Can you confirm that?

Chris
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

I will suggest that you put "C:\Program Files\Java\jdk1.4.2_15\bin;C:\Program Files\Java\jdk1.4.2_15\jre\bin" at the first position in your PATH.

Yes that is correct that a JRE don't have a java compiler - and it isn't 'javac' that you are using with 'java -version'.
Chris Wang
Ranch Hand

Joined: Jan 13, 2004
Posts: 34
Hi Lane,

There was no difference when I put "C:\Program Files\Java\jdk1.4.2_15\bin" and "C:\Program Files\Java\jdk1.4.2_15\jre\bin" at the first position of my PATH because I just need javac command which sits in "C:\Program Files\Java\jdk1.4.2_15\bin". It doesn't make sense to me putting "C:\Program Files\Java\jdk1.4.2_15\jre\bin" into my PATH.

Thanks,
Chris
Chris Wang
Ranch Hand

Joined: Jan 13, 2004
Posts: 34
Sorry Rene, I misspelled your name.

Chris
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi Chris, can you post your entire PATH here? Might be able to spot something
Chris Wang
Ranch Hand

Joined: Jan 13, 2004
Posts: 34
Hi Martijn,

Remember I set my PATH empty before I ran javac and java command under C:\Program Files\Java\jdk1.4.2_15\bin

But anyways here is my PATH:
PATH=C:\Program Files\Windows Resource Kits\Tools\;C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\PROGRA~1\IBM\Rati
onal\SDP\6.0\VoiceToolkit\WVS\ViaVoice\bin;C:\PROGRA~1\IBM\Rational\SDP\6.0\VoiceToolkit\engines\ViaVoice\bin;C:\PROGRA~
1\IBM\Rational\SDP\6.0\VOICET~1\engines\IBM\ibmtts\bin;C:\PROGRA~1\IBM\Rational\SDP\6.0\VOICET~1\engines\IBM\ibmtts\lib;
c:\Program Files\IBM\WebSphere MQ\Java\lib;C:\Program Files\ThinkPad\Utilities;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS
\System32\Wbem;C:\Program Files\IBM\Infoprint Select;C:\Notes;C:\Program Files\XLView;C:\lotus\compnent;C:\Utilities;C:\
Program Files\ThinkPad\ConnectUtilities;C:\WINDOWS\Downloaded Program Files;C:\Program Files\IBM\Personal Communications
\;C:\Program Files\IBM\Trace Facility\;C:\Program Files\Hummingbird\Connectivity\10.00\Accessories\;;C:\PROGRA~1\IBM\SQL
LIB\BIN;C:\PROGRA~1\IBM\SQLLIB\FUNCTION;C:\PROGRA~1\IBM\SQLLIB\SAMPLES\REPL;C:\Program Files\IBM\WebSphere MQ\bin;C:\Pro
gram Files\IBM\WebSphere MQ\Java\bin;C:\Program Files\IBM\WebSphere MQ\WEMPS\bin;C:\Program Files\IBM\Rational\SDP\6.0\r
untimes\base_v51\bin;C:\Program Files\Java\jdk1.5.0_12\bin;C:\Program Files\Java\jdk1.5.0_12\jre\lib\ext;C:\MinGW\bin;C:
\usr\was6nd\wasapps\lib\remedy_native\api700p002win\lib;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Q
uickTime\QTSystem\;C:\downloads\ant\apache-ant-1.7.0\bin;;C:\FPC\2.2.0\bin\i386-Win32;C:\Program Files\UWIN\usr\bin\

Thanks,
Chris
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi Chris,

OK, you've got several items in your path which might contain a version of javac. I recommend you overwrite your PATH temporarily and have it only contain the path to the javac you really want to use.

e.g.

PATH=C:\Program Files\Java\jdk1.4.2_15\bin
echo %PATH%
javac <source file>
Chris Wang
Ranch Hand

Joined: Jan 13, 2004
Posts: 34
Hi Martijn,

I did the exactly same steps as you provided, but there was no difference.
Could you please do me a favour? Please download a windows version jdk 1.4.2 if you don't have one and try it out on your machine, see what happens.

Thank you very much!

Chris
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

I get the same as you, major version of 46! I guess it must be a compatibility mode thing..
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Very peculiar; I don't think Java 1.4.2 is version 46, but 48. I think 46 is Java1.2. See this Sun thread.

How on earth do you get a Java1.2 class type? Have you got Oracle anywhere in your PATH? It has a reputation for installing old versions of Java and putting them first in the PATH. Edit your PATH by putting your up-to-date Java version at the beginning of the PATH, and try again.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hey all, yeah this is starting to weird me out! I took my own advice [how humble of me ] and cleared out everything from my PATH except for the javac in my 1.4.2 version of the JDK, I still got a version 46. I then tried compiling with a 1.5 JDK and still got a 46... I'm now going to go and get coffee and then investigate my PATH again.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Did you clear both the system and user PATH??
[ September 08, 2008: Message edited by: Rene Larsen ]
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Originally posted by Rene Larsen:
Did you clear both the system and user PATH??

[ September 08, 2008: Message edited by: Rene Larsen ]


Yep, just tried it again, same result... (tried to see if Verbose gave some more options)

C:\Java\j2sdk1.4.2_18\bin>echo %PATH%
C:\Java\j2sdk1.4.2_18\bin

C:\Java\j2sdk1.4.2_18\bin>javac -verbose Foobar.java
[parsing started Foobar.java]
[parsing completed 16ms]
[loading C:\Java\j2sdk1.4.2_18\jre\lib\rt.jar(java/lang/Object.class)]
[loading C:\Java\j2sdk1.4.2_18\jre\lib\rt.jar(java/lang/String.class)]
[checking Foobar]
[loading C:\Java\j2sdk1.4.2_18\jre\lib\rt.jar(java/lang/System.class)]
[loading C:\Java\j2sdk1.4.2_18\jre\lib\rt.jar(java/io/PrintStream.class)]
[loading C:\Java\j2sdk1.4.2_18\jre\lib\rt.jar(java/io/FilterOutputStream.class)]
[loading C:\Java\j2sdk1.4.2_18\jre\lib\rt.jar(java/io/OutputStream.class)]
[wrote Foobar.class]
[total 172ms]

Looked at class file, same 46 number. Ran the following code against it:



Got 46.0 as an answer, can't see anything obvious in Google either... This has definitely got me curious!
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

JDK 1.4 does default have:

Generated .class files compatibility: 1.2
Source compatibility: 1.3

J2SDK 1.4.2 - javac

Standard Options

-source release
Enables support for compiling source code containing assertions.

When release is set to 1.4, the compiler accepts code containing assertions. Assertions were introduced in J2SE 1.4.

When release is set to 1.3, the compiler does not support assertions. The compiler defaults to the 1.3 behavior if the -source flag is not used.


Cross-Compilation Options

By default, classes are compiled against the bootstrap and extension classes of the platform that javac shipped with. But javac also supports cross-compiling, where classes are compiled against a bootstrap and extension classes of a different Java platform implementation. It is important to use -bootclasspath and -extdirs when cross-compiling; see Cross-Compilation Example below.

-target version
Generate class files that will work on VMs with the specified version. The default is to generate class files to be compatible with the 1.2 VM in the Java 2 SDK. The versions supported by javac in the Java 2 SDK are:

1.1
Ensure that generated class files will be compatible with 1.1 and VMs in the Java 2 SDK.
1.2
Generate class files that will run on VMs in the Java 2 SDK, v 1.2 and later, but will not run on 1.1 VMs. This is the default.
1.3
Generate class files that will run on VMs in the Java 2 SDK, v 1.3 and later, but will not run on 1.1 or 1.2 VMs.
1.4
Generate class files that are compatible only with 1.4 VMs.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Ah as I suspected then! Thanks for confirming it .
Chris Wang
Ranch Hand

Joined: Jan 13, 2004
Posts: 34
Hi All,

Thank you very much, guys.
Now the problem has been clear -- Cross-Compilation!!!

Chris
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Well, well . . . I have never seen that before.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Originally posted by Campbell Ritchie:
Well, well . . . I have never seen that before.

Tell me about it, I had just finished going through this when one of the new grads introduced me to another grad as "The Java Guru". After I'd finished choking on my coffee I had to show them this thread, it provided some much needed disillusionment .

Oh and thanks for resolving this Rene! If you ever want to train some grads.......

[ September 08, 2008: Message edited by: Martijn Verburg ]
[ September 08, 2008: Message edited by: Martijn Verburg ]
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

It is always a pleasure to be able to help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unexpected java version in class file