Java 9 is almost here, is it time to switch?

Java 9 is almost here. Although the update is mostly comprised of smaller quality-of-life improvements for developers, it does feature a major change in how Java works. Jigsaw is the main component worth mentioning with this update. Some devs are looking forward to it, but some seem to be have a negative view, even before the release has dropped.

Oracle extended the deadline for delivery so that it could sort out the issues with the Java Platform Module System, or Jigsaw, which didn’t help. But there are lots of other gems hidden away in the specs. Upon closer inspection, additional security features and performance enhancements could make the release worth migrating to.

Wise people say good things come to those who wait, so let’s take a closer look at some features of the latest update — including Jigsaw — to see if Java 9 will deliver what we’re hoping for.

Modernisation and new APIs

JShell officially adds native REPL (Read-Eval-Print-Loop) to Java for the first time, so you can do away with the unofficial workarounds that you’re probably using now. JShell comes with its own API, and you can read the API specs here ahead of the official release.

There are a number of small tweaks to bring Java up-to-date. The javadoc tool will now output HTML5, and Java 9 also has full support for HTTP/2, which will allow it to leverage all of its important speed benefits.

Updates that resolve issues related to concurrency and parallelism are also included. Java 9 supports interfaces that support the Reactive Streams publish-subscribe framework, CompleteableFuture API tweaks, and improvements like support for timeouts, subclassing, delays, and other methods.

New Features Flow Into Streams

The Streams API is a much-loved feature added in Java 8, which will be a tough act for Jigsaw to follow. Streams allowed developers to begin aggregating operations from a sequence of objects.

Java 9 will make the work of developers even more streamlined, with a few additional utility methods being added to the API:

  • Iterate – which solves past issues with non-terminating loops.
  • takewhile and dropwhile – Both of these methods are predicate interfaces. As their names suggest, takewhile will take all values up until the point that the predicate returns false, whereas dropwhile drops all values until the predicate fails.
  • ofNullable – If the value is null, the new ofNullable method will return empty Optionals. This removes the need to have null checks throughout the code, and avoids NullPointerExceptions.

Project Jigsaw

Modularity is a long-sought idea in the world of Java, and Project Jigsaw is an attempt to add it. It’s arguably the biggest change that Java 9 introduces.

Jigsaw seeks to create a scalable module system. It will hopefully make it easier to scale applications down to small devices, which is good news; developers will only need to include the modules they need.

Jigsaw is also about improving security, and providing overall optimisation and performance boosts.

JAR files were a decent attempt at modularization, but they didn’t create a fully modular environment in the way that Jigsaw supposedly will. This is probably the part of Java 9 most worthy of your attention.

Is Java 9 Worth Adopting?

The official release of Java 9 will drop on September 21st, 2017. Most of the changes that it will bring are pretty minor, so there isn’t much reason to adopt yet unless you were looking forward to the modularization that Project Jigsaw brings. If you like to be on the bleeding edge, however, Java 9 offers some interesting possibilities. It doesn’t go as far as we’d like in some areas, but given the huge delays, it’s a miracle that it’s being released at all.