9

It is to my understanding that Java JREs are backwards compatible, if you write a program in Java (JDK) 7, it will run with Java (JRE) 8.

I have a couple of programs I developed in Java 8, and have .jar and EXE files that I built when I finished them, and they always ran fine. However, after installing Java JDK 11 (11.0.2), these old .jar files break...

  • A couple of them still run, but their GUIs have expanded, with buttons and images being bigger than before, and in some cases blurry
  • One program just doesn't run at all, trying to run it in a console gives an exception: "Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: javax/activation/ActivationDataFlavor"

I understand that this class and some other javax classes have been removed from JDK 11, so from a development standpoint you couldn't use them anymore without a tool such as Maven. But I do not understand why installing JDK 11 has any effect on my old jars, as I didn't install a new JRE, and even if one came with it, it should be backwards compatible?

Too add to this, I use Apache NetBeans 10, it worked fine with Java 8, but after I installed JDK 11, NetBeans 10 still ran but its loading window was big and blurry, and the IDE's images are blurry, and all the text is bigger.

So why is installing JDK 11 having these negative effects on older programs?

Note - I have tried associating the jars/EXEs with javaw.exe from JRE version 8 (201), however, they all still have the same issues.

Danjo
  • 103
  • 1
  • 1
  • 5
  • 2
    JDK11 should run your old software, but it doesn't contain all the classes it used to anymore, most notably J2EE. You need to add those to the classpath separately. – daniu Jan 30 '19 at 11:40
  • 1
    Each JDK *includes* a JRE and depending on what installation options you chose, it will overwrite existing JREs or changing the default JRE. – Holger Jan 30 '19 at 12:31
  • 1
    You can continue to use JAF as before, you don't need to change any code. Instead you just need to download the standalone version of JAF and deploy it on your class path. The dropping of JAF from Java SE has been flagged for a long time. – Alan Bateman Jan 30 '19 at 16:01

2 Answers2

6

Java tries to be backward compatible but sometimes breaking changes are necessary to evolve the ecosystem. Until now breaking changes were shipped with major release e.g. Java 9, 10, 11. In your case you are most likely affected by Java 11's JEP 320: Remove the Java EE and CORBA Modules.

Remember that Java 8 was released in 2014. For 5 years Oracle and the Java community provided patches and security fixes for Java 8 but doing this forever is impossible.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
  • So say a program was developed using JDK 8, and was released for other people to use, and one day a new Java JRE release comes out and users install it, there is a chance that they won't be able to use the program released to them anymore? – Danjo Jan 30 '19 at 11:49
  • 2
    @Danjo any sensible software will state in manual which versions of JDK are needed to run it. Often the right JDK is shipped as part of the software e.g. IntelliJ does that since it runs on Java 8. If a user wants to try a different JDK that's up to them, but it might not be supported. – Karol Dowbecki Jan 30 '19 at 11:52
  • Sorry if I am asking a dumb question here, but isn't it the JRE that should run the jars and EXEs that have already been built? Why does installing a new "development kit" have an effect on already compiled programs? – Danjo Jan 30 '19 at 11:56
  • 1
    @Danjo `javac` compiles to bytecode. This bytecode is a `class` file that is later run by JVM and transformed into native code. Two step process unlike say C where `gcc` produces native code directly. https://stackoverflow.com/a/48153/1602555 – Karol Dowbecki Jan 30 '19 at 12:02
  • But from the main Java Download page, which most non-developers would use, you only download (version 8 201) of the Runtime? I guess what I'm asking is basically, does it make sense that downloading JDK 11 has effects on already existing programs (Including NetBeans), and the only was to fix it is by uninstalling JDK 11? Response to your edit: so from a jar there is still compiling to be done and that's where the issue is with JDK 11 and removed classes? – Danjo Jan 30 '19 at 12:05
  • 1
    @Danjo if your program doesn't come with a bundled JVM than find the program documentation for said program and read which which JVM versions are supported. You can usually install multiple different JVMs and use program startup options to choose which to use. You are not restricted to just one Java version. – Karol Dowbecki Jan 30 '19 at 12:07
3

The issue you are facing is likely not an incompatiblity w.r.t. the bytecode. It is just a missing class.

Java 11 dropped the support of some old technologies - for example Java Applets. If you run a Java 8 Applet in a Java 11 JDK / JRE you will get a ClassNotFound exception just because Java 11 does not provide the class / jar.

Similarly for JavaFX, which still exists, but is not longer part of the Java Distribution. You have to add it as a separate Jar.

I believe it would be possible to add these classes to a project. Personally I would like to see a port.

Christian Fries
  • 16,175
  • 10
  • 56
  • 67