Vaibhav Agarwal
Vaibhav Agarwal

Reputation: 1144

Java Runtime compilation

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.

Upvotes: 0

Views: 194

Answers (1)

Gimby
Gimby

Reputation: 5274

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.

Upvotes: 1

Related Questions