0

I have often come across the phrase Java X runtimes compiled against Java Y. Could someone explain what does this statement actually mean? Is there a condition where X has to be greater than or equal to Y, or can it be anything? How does this work with respect to JVMs and JDKs?

Forgive me for not being able to understand the logic here.

1
  • 1
    In short it means you compile the source with a different version of the Java JDK then on the executing target. e.g. With a JDK version 8 you are able to compile classes to be executed with JRE version 6 javac -source 1.6 -target 1.6 Main.java Commented Mar 10, 2015 at 9:09

1 Answer 1

1

Its a bit difficult to be sure what you're really asking about without you giving an example of where you read that.

If something says "compiled for Java 6" then you can safely use that on any Java runtime starting from Java 6 and up, but it will fail with a "unsupported major class version" error on Java 5 runtimes and below.

So in your own words, X must indeed by equal to or greater than Y. You pick the minimal Java runtime version that you want to support upon the moment that you compile the code.

For a long time now library developers try to keep their code compatible with Java 5; its only recently that I have seen compatibility rise up to Java 6 minimally. The reason for compiling for such old and unsupported runtimes is simple; it is to make libraries work on the largest amount of runtimes that is installed and in use. You can't naturally assume that everyone has upgraded to modern Java runtimes already, there are still plenty of legacy programs that require a Java 5 runtime.

Luckily as SubOptimal already comments, you're not forced to use a Java 5 JDK to actually compile code for Java 5 compatibility; you can use newer JDK's to produce bytecode compatible with older runtimes too. But you can't use say Java 6 to compile code with Java 8 features or produce Java 8 bytecode, of course.

Sign up to request clarification or add additional context in comments.

3 Comments

One of the instances where I have read it on one of the anwers for stackoverflow.com/questions/24657418/spring-core-3-2-9-java-8 - "Spring 3.2.x will only support Java 8 runtimes compiled against Java 7. You cannot use "static interfaces" as that is a Java 8 feature and will not compile against Java 7."
Besides, regarding when you say you can use newer JDK's to produce bytecode compatible with older runtimes too - I can create a bytecode compatible with Java 7 from JDK 1.8, but I can't have Java 8 bytecode to run on JVM 7 for that matter. Am I correct?
@VaibhavAgarwal sorry for the late response. You are correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.