This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes java 1.4 and 1.5 compatable ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java 1.4 and 1.5 compatable ?" Watch "java 1.4 and 1.5 compatable ?" New topic
Author

java 1.4 and 1.5 compatable ?

merwin pinto
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
Hi ,
Suppose i compile a java file with java 1.5 ......
then try to run it in java 1.4 ..... Will there be version mismatch errors ?? is there some amount of Upward compatablity in Java ??
thank you
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Originally posted by merwin pinto:
Hi ,
Suppose i compile a java file with java 1.5 ......
then try to run it in java 1.4 ..... Will there be version mismatch errors ?? is there some amount of Upward compatablity in Java ??
thank you


If you do not specify the -target option to your 1.5 compiler, then no, it will not run.

It works like this:
In order for your code to run on 1.4, it must be "1.4 source compatible". That means you must not use any 1.5 language features (you can use the 1.5 keyword enum as an identifier in this case) and specify the -source option to the compiler with a value of 1.4 (or lower). This also means you must specify a -target value of less than 1.5, which means your code will run on a non-1.5 VM.

However, if you are 1.5 source compatible (you use 1.5 features), you must also be "1.5 target compatible". This means you cannot run on any JVM less than version 1.5.

Now, the 1.5 compiler, by default, already sets the -source option to 1.5 and the -target option to 1.5. So, by default (no compiler options specified), code compiled by a 1.5 compiler will not run on a 1.4 VM for this very reason.

Also, the 1.4 compiler has a default -source and -target option of 1.2. The only addition to the language is the 'assert' keyword, which must be "switched on" explicitly.

Hope it all makes sense


Tony Morris
Java Q&A (FAQ, Trivia)
merwin pinto
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
hey Tony,
Thanks a lot for the information.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java 1.4 and 1.5 compatable ?
 
Similar Threads
Difference in Swing 1.4 and 1.5
SCWCD - Java 1.4 / 1.5?
Where can I find java 1.5 class diagram??
Unable to get Eclipse working
Validity of SCJP for JAVA5