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