Core Java

Java 8 vs Java 11

This is an article that compares Java 8 vs Java 11. We will see the various features and enhancements from each Java version.

1. Introduction

Java 8 and Java 11 are the two current LTS or Long Term Support versions of java. In this article, we take a look at what new features each version brought. We will compare the features and see if we should upgrade from Java 8 to Java 11.

2. New Features introduced in Java version 8

Java 8 vs Java 11

With Java version 8, Oracle moved away from the Binary Code License(BCL). Oracle released java under two licenses from Java 8 onwards.

  • GNU General Public License v2 with Classpath exception (GPLv2+CPE) provided by OpenJDK,
  • The commercial license under Oracle product or service, i.e., Oracle Technology Network License Agreement (ONTLA).

Besides this significant change, Java 8 introduced several new enhancements. They are as follows:

  • Lambda. With Lambda expressions, we can write Java programs in the functional style. To accommodate Lambda functionality, java introduced a few classes and methods like Method Reference, forEach, Functional Interfaces, to name a few.
  • Developers implemented sweeping changes to the way java deals with Date and Time objects. They implemented a new date/Time API.
  • Java allows default methods in interfaces and can even have method bodies.
  • Nashorn engine is a new Javascript engine to embed JavaScript code.
  • StringCollector class is a new class for string manipulation with delimiters
  • Java 8 introduced the concept of Streams. A Stream is a sequence of objects that we can do operations on and can pipeline.
  • Developers implemented a new Collectors class. The Collector class provides reduction operations used with streams.
  • A Base64 class for encryption and decryption
  • Java version 8 introduced a new method, parallelSort in the arrays class for sorting Arrays in parallel.
  • There were significant changes in encryption-decryption algorithms.
  • The Java server Socket Extension JSSE enables TLS1.0 and TLS 2.0 protocols by default.
  • Java 8 introduced a new command, jjs, for the Nashorm JavaScript Engine.
  • Java 8 introduced a new command-line tool called jdeps.

These are just some of the enhancements done in Java version 8.

3. New Features introduced in Java version 11

The most important features introduced in Java version 11 are as follows:

  • A new, experimental garbage collector: ZGC or Z Garbage Collector, was added as a preview feature.
  • Java 11 introduced a new method toArray in the Collections interface.
  • The ChaCha20 and ChaCha20-Poly1305 ciphers introduced that replace the old, less secure ciphers.
  • Java provided a new launcher to run a single Java source code file.
  • A new command line flag to control the number of compiler threads. The flag is XX:+UseDynamicNumberOfCompilerThreads.
  • There is a new reserved type name var. The var keyword is available for Lambda expressions.

4. Removals in Java 11

While Java 11 introduced many features, developers also removed large chunks of code. The removals are as follows:

  • Java 11 codebase removed the Applet Viewer tool that Java version 9 deprecated this module.
  • The AWT utility class.
  • Bundled Fonts.
  • CORBA and related modules.
  • Java version 11 removed the Java Control Panel, JRE auto-Update mechanism, Java Plugin, and Webstart related code. From Java 11, the JRE does not get installed along with the JDK. The JRE is no longer required because Java version 11 removed the Applet-related code. As per Oracle’s release notes:

In Windows and macOS, installing the JDK in previous releases optionally installed a JRE. In JDK 11, this is no longer an option. In this release, the JRE or Server JRE is no longer offered. Only the JDK is offered. Users can use jlink to create smaller custom runtimes.

Oracle release notes

  • Java FX modules were separated and removed from the main code.
  • The SNMP modules.
  • Java Mission Control (JMC). Just like Java FX, it is available separately.
  • The Thread.destroy() and Thread.stop(Throwable) methods

5. Depreciations in Java 11

The main features deprecated in Java version 11 are as follows:

  • Two command-line arguments:-XX:+UnlockCommericalFeatures and XX:+LogCommercialFeatures were deprecated.
  • The jcmd commands VM.check_commercial_featuresand VM.unlock_commercial_features were also deprecated.
  • The jjs tool.
  • Java 11 deprecated the Nashorn JavaScript engine and its related modules.
  • The Pack200 API from java.util package.
  • Methods like acceptSecContect,getMIC,initSecContect,unwrap,verifyMIC and wrap were deprecated. These methods were a part of the GSS-API security context.
  • The ThreadPoolExecutor class

6. Java 11 Performance and Security Improvements

Above, we discussed the Language and tool-related enhancements and features introduced in Java version 11. Along with these enhancements, there were some mission-critical security enhancements. The updates are as follows:

  • Standardized HTTP Client implemented.
  • Implementation of TLS 1.3 support
  • Java developers have changed several features to JSSE (Java Server Sockets Extension) package to support TLS 1.3.
  • Developers have implemented more secure and better cryptographic algorithms ChaCha20 and Poly1305 to replace the older, less secure RC4 cipher algorithms.
  • Developers have implemented New Key exchange algorithms Curve25519 and Curve448. These have replaced the Diffie-Helman elliptic curve scheme that currently exists. They make the key handshakes more secure.
  • Nest-Based Access Control: Java allows the nesting of classes in a single source code file. However, until Java version 11, the Java compiler compiled each of the nested classes as separate classes. To support nesting, the compiler had to build synthetic or bridging methods and access variables, and so on. This extra processing and adjustments was an overhead. Java 11 improves the way compilers handle nesting. As per the author of the feature:

Introduce nests, an access-control context that aligns with the existing notion of nested types in the Java programming language. Nests allow classes that are logically part of the same code entity, but which are compiled to distinct class files, to access each other’s private members without the need for compilers to insert accessibility-broadening bridge methods.

Feature documentation

7. Reasons to upgrade from Java 8 to Java 11

  • Java versions 9, 10, and 11 have made significant changes that have improved the performance and security of Java applications.
  • Garbage Collection has also improved with ZGC and Epsilon garbage collectors.
  • Java now supports TLS 1.3, which is more secure than its predecessors.
  • Applets have always caused security problems—Java 9 deprecated applets. Java 11 removed the code related to it entirely.
  • Java 11 implemented a new heap profiler and low overhead flight recorder.
  • It introduced the ability to run a single Java source code file.
  • Java 11 removed the CORBA and Java EE modules that are out-of-date and pose security problems.
  • Developers also introduced the var keyword, which significantly improves the ease of coding.

Oracle does not support Java version 8 and has no more public updates and no security updates. Java version 11, on the other hand, Oracle still supports. Due to all these reasons, one should migrate from Java 8 to Java 11.    

8. Summary

That was a java 8 vs java 11 article, where we saw the various features and enhancements from each Java version. We also took a look at all the removals and deprecations in Java version 11. Looking at all the security enhancements and performance improvements, it is a good idea to upgrade from Java version 8 to Java version 11 despite the fact that Oracle still supports Java version 8.

Reshma Sathe

I am a recent Master of Computer Science degree graduate from the University Of Illinois at Urbana-Champaign.I have previously worked as a Software Engineer with projects ranging from production support to programming and software engineering.I am currently working on self-driven projects in Java, Python and Angular and also exploring other frontend and backend technologies.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
surya
surya
2 years ago

Thank you for this comprehensive and useful article.

Back to top button