Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 802
amit kumar Avatar asked Dec 18 '09 11:12

amit kumar


People also ask

Can JDK and JRE be different versions?

The JDK and JRE versions can be different on the same computer. Multiple JDK and JRE versions are allowed on the same computer; it is better to find out which version is configured in the system classpath to run or compile the Java program.

Can newer JRE versions run Java programs compiled with older JDK versions?

You would not encounter any problems - that's the magic of Java -it's backwards compatible. You can run almost all code from Java 1 on Java 8. There's no reason why Java 6 code won't run on a Java 8 Runtime.

Is Java 8 backwards compatible?

Incompatibilities between Java SE 8 and Java SE 7. Java SE 8 is strongly compatible with previous versions of the Java platform. Almost all existing programs should run on Java SE 8 without modification.


1 Answers

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.

like image 80
Vincent Ramdhanie Avatar answered Oct 16 '22 03:10

Vincent Ramdhanie