Does the Java language support backward compatibility throughout the history?

Has Java always supported backward compatibility of source code?

More precisely: considering the two versions of Java X and Y with X <Y, is any program for Java X also a valid program for Java Y with the same semantics? For example. X = Java 2 (or 1.2 with the old numbering) and Y = Java 5.

Or there is only compatibility at the JVM level: for example. class compiled for JVM 1.2 can be controlled by JVM 5?

If you can run Java 2 code on Java 5 (or 6 or 7), what are the exact steps that I have to follow? Compile directly using the Java 5 compiler? Compile using Java 2 compiler and run on JVM 5?

+7
source share
6 answers

Sun, and now Oracle, has always been very careful with backward compatibility with Java.

Binary compatibility You can run Java code compiled in older versions in new versions unchanged. However, there may be slight incompatibilities.

Source compatible . Code originally written for an older version of the JDK should almost always compile unchanged using the new Java compiler, but there are a number of minor incompatibilities. One of them is the enum keyword, added in Java 5; in older versions of Java, enum was a valid identifier, but not in Java 5. Also, importing classes from the package was removed by default (I think starting with Java 1.4). Therefore, you cannot:

 import SomeClassName; 

more on Java 1.4 or later.

The documentation for each version of the JDK has a document on backward compatibility with previous releases, which lists the details.

+4
source

Running witg Java 1.5 enum become a reserved word. Thus, any Java 1.4 source code containing enum been broken since 1.5

+4
source

As far as I know, JVMs are backward compatible. A class compiled using JDK 1 will work in the latest version of JRE 7. Libreira is definitely not 100% compatible. Some methods are deprecated (and subsequently removed). Some classes have changed behavior in (usually) subtle ways that cause programs to behave differently.

+3
source

You can always run a newer version of the JDK, and then the one used for compilation. Another way is not possible (unless you compile with the -target option).

You might want to read this document (in particular, the section "Cross-compilation options"), which explains the target parameter and default behavior

+2
source

Java is generally compatible with previous versions, but in any case there may be a problem with migration. For more details see My article on migration from JDK 6 to 8

0
source

You can see the backward compatibility analysis of the Java (Jre) library classes here: http://abi-laboratory.pro/java/tracker/timeline/jre/

The report is generated by the japi-compliance-checker tool.

enter image description here

0
source

All Articles