I am programming in Eclipse. I never change anything about the default compile setting of Eclipse, or anything else.
If I have JDK 7 installed on my computer. Should my compiled Runnable JAR have any problem running on an older JRE, assuming that the older JRE supports all my programs features?
For example, if I program an application in Eclipse, with the latest JDK installed - should the program have a problem running on a slightly older JRE?
If the answer to this is "yes" - How can I change this? How can I allow my program to run on older JREs than my JDK? Thanks
Your code will only run on JRE 6 of you compile it for JRE 6. Check your compiler settings (Project->Properties->Java Compiler) and make sure that you compile for Java 6, otherwise users will get an UnsupportedClassVersionError if they don't have Java 7 installed.
You also have to make sure to either not use any Java 7 features (e.g. java.nio.Path), or install the Java 6 JDK and use it to compile your application, otherwise you'll get missing method/class exceptions when running the application on Java 6 (you'll instead get compile time errors when using JDK 6).
The Java runtime that Eclipse uses does not have to be the same that your project uses. You can set the runtime of your project in the project's properties:
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2FgettingStarted%2Fqs-ProjectConfiguration.htm
Java 7 is backwards compatible, meaning older Java programs will run in this version of Java. However, Java versions are never forwards compatible. Meaning a program written in Java 7 will not necessarily compile in Java 6 and a program written in Java 6 will not necessarily compile in Java 5. That is because Java 7 contains features that Java 6 does not contain, like strings in switch statements, and Java 6 contains features Java 5 does not contain, like scripting language support (see https://en.wikipedia.org/wiki/Java_version_history for an overview).
Also lack of forwards compatibility means Java programs compiled in a newer version of Java will not run on an older version of the Java runtime. The java compiler specifically protects compiled java class files with a version identifier to not run these classes when they are compiled in newer version of Java.
If you are careful to avoid Java 7 features you can write a Java program in Java 7 that will compile and run in Java 6. If you know however that your program needs to run in Java 6 it is best to set your project's runtime to Java 6.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With