5

Does Java support running in compatibility mode? In other words if we have JDK 8 install on system, can it be configured to run my application on 7 or previous release using the same installation ?

I can give one example like IE-11 can be switch to run as IE 8, 9, or 10 based on the compatibility option.

Laurel
  • 5,965
  • 14
  • 31
  • 57
  • http://www.oracle.com/technetwork/java/javase/8-compatibility-guide-2156366.html – Ankur Singhal May 04 '16 at 06:45
  • No, there's no such compatibility mode. If you want to be absolutely sure, you'll have to install additional JDKs and test the program on them. – Kayaman May 04 '16 at 06:47
  • @Gimby I don't think the question is about compiling, but about whether a Java 7 program can run on Java 8. --- Anyway, the answer is that (with very few exceptions), Java is backwards compatible, without need for a compatibility mode. See link in first comment. – Andreas May 04 '16 at 07:12
  • If you want to prevent accidentally accessing of new Java 8 classes or members, you need the JRE library of Java 7 to specify it as boot class path when compiling. This implies, that you will have a Java 7 installation anyway. Besides that, even compatibility modes don’t spare you from doing real tests on the real thing at some time… – Holger May 04 '16 at 08:16

1 Answers1

2

I agree with the comment of Kayaman. There are 2 types of incompatibilities that could occur: bytecode changes (some feature supported in 8 and not in 7 - new Java versions tend to be upward compatible - so 8 will be able to run all 7-targeted code) and library changes which is more problematic.

If you have compiled with Java 8 targeting 7+, your bytecode will be compatible with Java 7 JVM, but you have no guarantee that it will run with Java 7 libraries.

Your best bet is then to compile and run with Java 7 - and it will (most probably) run with Java 8.

Then there are other changes that may impact your application (GC performance for instance).

GdR
  • 313
  • 1
  • 8