Giorgio
Giorgio

Reputation: 5183

Has the Java language maintained source-code backward compatibility throughout its history?

Has Java always maintained source-code backward compatibility during its development?

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

Or is there only compatibility at the JVM level: e.g. a class compiled for the JVM 1.2 can be run by the JVM 5?

If it is possible to run Java 2 code on a Java 5 (or 6, or 7), what are the exact steps that I have to follow? Compile directly with a Java 5 compiler? Compile with a Java 2 compiler and run on JVM 5?

Upvotes: 11

Views: 1117

Answers (6)

linuxbuild
linuxbuild

Reputation: 16153

You can look at 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

Upvotes: 2

Sergey Ponomarev
Sergey Ponomarev

Reputation: 3201

Java is generally compatible with previous releases but anyway it may be a lot f issues with migration. See my article about migration from JDK 6 to 8 for details

Upvotes: 0

Jesper
Jesper

Reputation: 207016

Sun, and now Oracle, have always been extremely careful with backward compatibility with regards to Java.

Binary compatibility: You should be able to run Java code compiled with older versions on newer versions without modification. There might, however, be small incompatibilities.

Source compatibility: Code originally written for an older JDK version should almost always compile without modification with a newer Java compiler, but there are a number of small incompatibilities. One of them is the enum keyword added in Java 5; on older versions of Java, enum was a valid identifier, but not on Java 5. Also, importing classes from the default package has been removed (I think since Java 1.4). So you can't do:

import SomeClassName;

anymore on Java 1.4 or newer.

In the documentation of every JDK release there is a document about backward compatibility with previous releases, which lists the details.

Upvotes: 5

MK.
MK.

Reputation: 34597

As far as I know JVMs are backwards compatible. A class compiled with JDK 1 will work in the latest JRE 7. The libraires are definitely not 100% compatible. Some methods have been deprecated (and subsequently removed). Some classes changed behavior in (usually) subtle ways which will cause programs to behave differently.

Upvotes: 3

Robin
Robin

Reputation: 36621

You can always run with a newer version of the JDK then the one used for compilation. The other way around is not possible (unless you compile using the -target parameter).

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

Upvotes: 2

Steve Kuo
Steve Kuo

Reputation: 63134

Starting witg Java 1.5 enum became a reserved word. Thus any Java 1.4 source code containing enum became broken starting with 1.5

Upvotes: 4

Related Questions