Skip to content

16. Java 11 Transition

Ilkka Seppälä edited this page Oct 12, 2019 · 60 revisions

Overview

When writing this, Java Design Patterns version 1.22.0-SNAPSHOT supports Java 8. Breaking it down it means that the source code uses up-to Java 8 features, the code is built using Maven Compiler Plugin with target version of 1.8 and the code is executed using Java 8 runtime.

After Java 9 was released in 2017-09 there was a drastic change in Java's release schedules. New version would be released every 6 months instead of the old 2 years. New releases would be either rapid releases (supported only for 6 months) or LTS (long-term-support) that would be supported for longer time. The latest release at the moment is Java 13 (rapid release) that was released just a few days ago. The latest LTS version is Java 11. Naturally after Java 8 we want to move to the next LTS version.

Background Material

https://blog.codefx.org/java/planning-your-java-9-update/

https://blog.codefx.org/java/java-9-migration-guide/

https://www.infoq.com/articles/upgrading-java-8-to-12/

https://winterbe.com/posts/2018/08/29/migrate-maven-projects-to-java-11-jigsaw/

Preparing for the Transition

Switch from JDK8 to JDK11

After the Transition

Predicate::not provides an easy way to negate predicate lambdas or method references, again reducing the boilerplate in our code (see https://www.infoq.com/articles/upgrading-java-8-to-12/)

New methods on Optional give even more options for coding in a functional style when using an Optional instead of having to use clumsy if statements (see https://winterbe.com/posts/2018/09/24/java-11-tutorial/)

Streams have new methods ofNullable, dropWhile, takeWhile (see https://winterbe.com/posts/2018/09/24/java-11-tutorial/)

String has new helper methods (see https://winterbe.com/posts/2018/09/24/java-11-tutorial/)

InputStream finally gets a super useful method to transfer data to an OutputStream (see https://winterbe.com/posts/2018/09/24/java-11-tutorial/) #987

  • JShell is the REPL that allows us to run individual lines of code, or even scripts, in Java. It’s a nice way to experiment with new features, and we can use it locally on our development machines without having to adopt new versions of Java in our production application code. Can we utilize that?
  • HttpClient built in to the JDK. Can we utilize this? (see https://winterbe.com/posts/2018/09/24/java-11-tutorial/) #988
  • Multi release jar files is one of the tools library developers can use to support the needs of those using the latest versions of Java as well as those forced to use older versions. Can we utilize that? (see https://www.infoq.com/articles/upgrading-java-8-to-12/)
  • JLink is a fantastic tool made possible by the Java Module System which lets us package and deploy only the sections of the JDK that we really need. Can we utilize it? (see https://www.infoq.com/articles/upgrading-java-8-to-12/)
  • The default Garbage Collector has been changed to G1. Does this affect us?
  • The improvements in recent versions of Java can lead to a cost reduction. Not least of all tools like JLink reducing the size of the artifact we deploy, and recent improvements in memory usage could, for example, decrease our cloud computing costs.