Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JDK 7 class file backward compatibility with JDK 6

Tags:

java

java-7

Which features of JDK 7 (excluding invokedynamic because it is not used by java) causing a new class file version which is not compliant with JDK 6. It seams that all features could be implemented by compiler generating glue codes. For example String in switch statement could be implemented using repeated ifeq statements generated by the compiler. I want to able to give -source 1.7 -target 1.6 flags to compiler to be compliant with jre 6 and at the same time use project coin features in jdk 7.

like image 265
Deniz Avatar asked Jul 14 '11 20:07

Deniz


People also ask

Can program developed with Java 7 be run on Java 8?

Binary Compatibility Except for the noted incompatibilities, class files built with the Java SE 7 compiler will run correctly in Java SE 8. Class files built with the Java SE 8 compiler will not run on earlier releases of Java SE.

Is Java 1.7 and 7 the same?

all the way to 1.7, also known as Java 7) usually contain improvements to both the JVM and the standard library, so the two usually need to run together, and are packaged together in the JRE. If you are running any Java program on your computer, you have a JRE installed. The JDK is the Java Development Kit.

Can older JRE versions run Java program compiled with newer JDK versions?

As answered already you are mostly safe and most products and 3rd party libraries will simply work. However there do exist very rare cases where binary incompatibilities (ones where the class file compiled using older JDK will fail to run in the newer JVM) were introduced between JDK versions.

Are JDK versions backwards compatible?

Backward Compatibility Java versions are expected to be binary backwards-compatible. For example, JDK 8 can run code compiled by JDK 7 or JDK 6. It is common to see applications leverage this backwards compatibility by using components built by different Java version.


1 Answers

I haven't read the code for the compiler, but some of the new features must obviously have an impact on the bytecode.

"Simplified varargs method invocation" is really just a warning suppression, but it must leave some marker in the bytecode so that client code can display warnings differently.

"Try-with-resources" generates code that can handle a normal exception plus a second exception thrown during the finally block. The extra exception is stored using the new addSuppressed() method. This isn't exactly a class-file format change, but it clearly wouldn't work on earlier VMs.

"Multi-catch" also produces bytecode that's subtly different than any previous compiler could produce. Multiple entries in the exception table will now point to the same catch body.

like image 87
Craig P. Motlin Avatar answered Sep 23 '22 21:09

Craig P. Motlin