Since the public Java 6 SE JRE is getting closer to it's EOL (Nov '12), I'm considering porting my projects from Java 6 to Java 7. This would'nt be a big deal, if Apple would provide a Java 7 JRE for Mac OS X. But since Apple isn't willing to do so, I still have to support users which only have a Java 6 JRE.
Is there a way to compile Java 6 compatible binaries (class files) with the Java 7 javac? Certainly I'm aware that I can't use the new Java 7 features when doing so.
Thanks in anticiption!
It depends. If your program doesn't use the new Java 7 language extensions, then you can run the Java compiler with the
-source 1.6
and-target 1.6
options. But if you use Java 7 language extensions then-source 1.6
will result in compilation errors.That includes Java 7 language features ... and dependencies on Java 7 changes to the standard class library APIs. Also be aware that there are small number of behavioural differences (aka API bug fixes) that may cause code to run differently on Java 6 and Java 7. They should be described in the Java 6 to Java 7 transition document.
UPDATE - This probably no longer an issue for you anyway, because Oracle have released Java 7 for Mac OSX.
Yes, but in some cases no. In java 1.6 they didn't have the try with resources, switch with strings, or multi catch statements etc. So those parts of the program will not compile. But the idea of java is compile once, run everywhere; so code can work on old JVMs
i have jdk6 installed. if you check the man page of javac:
Stephen C's answer is correct, but not complete. Your Java 7 programs won't compile in Java 6 if they use Java 7 language features, but be warned subtle other bugs can still occur with one developer coding in Java 6 and another compiling Java 7.
Take for example java.sql.Driver. In Java 7, the interface gained an additional method.
Java 7 Developer This developer implements the Driver interface and uses the 'Override' annotation on the implemented additional Driver method. The program compiles fine as a Java 6 program because the class that the Java 6 compiler sees does have that method and the code gets checked in. Compiling the program as Java 6 does not mean that Java 6 compiler will automatically switch to use Java 6 source code!
Java 6 Developer The Java 6 developer attempts to build the code the Java 7 developer committed and gets a compilation error even though the Java 7 developer was not implementing any Java 7 language constructs.
Consequently, even though you could compile it as Java 6, I would recommend not doing this.