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?
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.
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?
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'.
Joined: Jan 13, 2004
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.
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.
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.
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.
-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.
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.
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 ]