Will an application made in JDK 14 run on a machine that has Java version 8 installed?

Tags: ,



My question stems from this… when you google “download java” the first result is this: https://www.java.com/en/download/

This prompts you to install java 8. If I’m creating an application using JDK 14, can I expect that application to run on a clients computer that has installed java from the link above (Java 8)? Additionally, what is that link installing that’s different from what I’d install from the Java SE 14 install page (https://www.oracle.com/java/technologies/javase/jdk14-archive-downloads.html)?

Answer

Will an application made in JDK 14 run on a machine that has Java version 8 installed?

The answer is “No1 … unless you do a lot of work at build time”. (See @andreos’ answer for an explanation of what happens if you try to run Java 14 code on Java 8.)

There are a couple of issues you need to address to make it work:

  1. Unless you use the --target option when you compile your code, the compiler will emit “.class” files with the class file version that correspond to Java 14. They won’t load on a Java 8 platform. The --help option should tell you what older target versions that javac accepts in Java 14.

  2. If you set the --target option to 8, your --source must be 8 or earlier. This means that you won’t be able to use newer Java language features (e.g modules)

  3. Separately to the above, your application needs to be compiled against the Java 8 class libraries. If your code uses classes, methods, etc introduced in Java 9 or later, it won’t run on Java 8.

The simple solution is to compile your application on a Java 8 JDK if you need to run it on a Java 8 platform.

Alternatively, if you want to use Java 9+ language features and APIs (or 3rd-party libraries written for Java 9+) you will need to forego supporting Java 8. There is no easy choice here.

1 – If you want to be pedantic, it will work if the user has both Java 8 AND Java 14 installed … and they run it using Java 14.


My question stems from this… when you google “download java” the first result is this: https://www.java.com/en/download/

I don’t understand why Oracle doesn’t address that problem. Business reasons, I guess.

But you could always include instructions for downloading an appropriate version of Java in >>your<< application’s documentation. Alternatively, use jlink + jpackage so that your users don’t need to download a JRE or JDK.



Source: stackoverflow