I want to have a source file which can compile with javac / ecj set to Java 5 but not Java 6 (even if the underlying Java runtime is Java 6).
This is to be certain that the compiler level is set correctly in Eclipse 3.5 running with Java 6 installed, but where the result needs to run on a Java 5 installation.
For java 1.4 I could use "enum" as a variable name (which fails under Java 5 and later) but I cannot locate a similar approach for Java 5 versus 6 (and later).
Suggestions?
No you can't develop java programs only with JRE. You will need JDK for compiling your programs. JRE provides only runtime environment,but JDK is something you will need to compile your code to make them executable by your JRE .
You can't run Java program without JVM. JVM is responsible in running a Java program, but the only file that can be executed by JVM is Java bytecode, a compiled Java source code.
The compiler produces a compiled class file with the same name as the public class or interface declaration; the file extension used for a compiled Java file is . class.
javac - Java programming language compiler.
There's nothing in the Java language that was removed between JDK5 and 6. The only thing which was added, as has been said, was the @Override
annotation being allowable on interface methods - no keywords. Hence you are left with library diferences as the only cause of breaking changes, I'm afraid.
These do exist, even in the core API; in an unusual fit of backwards-compatibility-breaking revelry they changed the signature of some methods on the ExecutorService
interface. This was because the generic signatures of the methods were overly restrictive. This was a pure library change (although, being part of java.util
, a pretty core library); nothing to do with any language-level modification.
For example, from JDK5 :
<T> T invokeAny(Collection<Callable<T>> tasks)
to JDK6:
<T> T invokeAny(Collection<? extends Callable<T>> tasks)
This means that any program which contained code implementing this interface in JDK5, would not have compiled against JDK6. A snippet is easy to create; just let your IDE create an empty implementation of the JDK5 interface and then build against JDK6.
Note: that the wildcard was added because the previous version would not have accepted a parameter like List<MyCallable<String>>
(i.e. the collection being typed by some subclass of callable) whereas the later version does.
Since JVMDI was removed and JVMPI was disabled in Java SE 6 (according to J2SE 6.0 release note), you could add a code using that API: it will not compile with J2SE 6.0, only 5.0. (as illustrated by this thread)
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