Major differences of OpenJDK 11 and OpenJDK 8

Solution Verified - Updated

Environment

  • OpenJDK 8
  • OpenJDK 11

Issue

  • What are the differences between OpenJDK 8 and OpenJDK 11?
  • Was there anything added or removed in JDK 11?

Resolution


Disclaimer: Links contained herein to an external website(s) are provided for convenience only. Red Hat has not reviewed the links and is not responsible for the content or its availability. The inclusion of any link to an external website does not imply endorsement by Red Hat of the website or their entities, products or services. You agree that Red Hat is not responsible or liable for any loss or expenses that may result due to your use of (or reliance on) the external site or content.


Major differences:

  • Log system: In OpenJDK 11, a.k.a Java 11, the log system was unified. See JDK 11 Logging mechanism with -Xlog Option

  • lib/ext and JRE directory: In OpenJDK 11, this directory was removed now with the existence of jlink support and the use of -classpath flag is necessary to add custom modules to the runtime. The solution How to create a Custom JRE using jlink explains the complete procedure to use jlink.

  • Several modules were removed, including CORBA see aforementioned link for specific details and complete list.

  • Reflection: reflection should be done via StackWalker rather than sun.Reflect, which was removed. JDK still has java.base/jdk/internal/reflect/Reflection, but set as internal inside a module named jdk.unsupported.

  • Deep reflection: user can add --add-opens flag at runtime option to make the code to access non-public members.

  • Like Java8, Java 11 has Long-term Support (LTS), in fact, the second LTS release after Java 8.

  • Java 11 has all the features of Java 10 and Java 9.

  • There are several features added to OpenJDK 11 (list below).

  • The boot class path has been mostly removed, ie. -Xbootclasspath and -Xbootclasspath/p options have been removed and only the -Xbootclasspath/a option was unaffected.

  • Illegal Access To Internal APIs: Non-public classes as well as classes from non-exported packages are inaccessible from outside the module and in case of access, a warning is emitted:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by example.class
	(file:...) to field com.example.class.field

Main features added on Java 11:

  • Running Java File with a single command: no need to do javac.
  • New utility methods in String class
  • Local-Variable Syntax for Lambda Parameters
  • Nested Based Access Control
  • JEP 321: HTTP Client
  • Reading/Writing Strings to and from the Files
  • JEP 328: Flight Recorder
  • JEP 318: Epsilon
  • JEP 320: Remove the Java EE and CORBA Modules
  • JEP 329: ChaCha20 and Poly1305 Cryptographic Algorithms
  • JEP 315: Improve Aarch64 Intrinsics
  • Shenandoah/ZGC Garbage Collector (Experimental)
  • JEP 335: Deprecate the Nashorn JavaScript Engine

To see the complete list of features: Content from www.oracle.com is not included.JDK 11 Release Notes and/or Content from www.oracle.com is not included.Consolidated JDK 11 Release Notes.

Migration Guide


See the [JDK 11 - Migration Guide](https://docs.oracle.com/en/java/javase/11/migrate/migration-guide.pdf) for more information on the migration to JDK 11.

Diagnostic Steps

For InaccessibleObjectException in a certain package, just add one more --add-opens, example:

For access of private methods without the access:

java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @11222

Add:

--add-opens java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED
Category
Tags

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.