Is is possible to build java code using JDK 1.6 to run on JRE 1.5?

amit picture amit · Dec 18, 2009 · Viewed 23.8k times · Source

Is there an option to build java code to run on JRE 1.5 when compiled using JDK 1.6?

PS: I am new to Java.

Answer

Vincent Ramdhanie picture Vincent Ramdhanie · Dec 18, 2009

If you compile your code with 1.6 then it will not run on 1.5. If you want it to run in 1.5 then you can compile the code with 1.5 and it would be able to run on both.

Try compiling with 1.5 and if there are errors then post them. The only way it will not compile on 1.5 is if you use specific 1.6 enhancements in your code.


To answer the real question.

  javac -target 1.5

See here for more details.