days
-6
-6
hours
-1
-8
minutes
-2
-8
seconds
-1
-1
search
Mini-series: Part 4

Manual on Java 11: One small step for the new Java release train, one giant leap for Java 8 users

Gabriela Motroc
Java 11
© Shutterstock / curiosity

New Java release, new series! This time, we invited nine Java experts to share their best and worst experiences with Java 11, the hacks they discovered so far, their tips & tricks and more. The series is coming to an end but not before we ask our experts one last question: How much do you care about Java 11?

Java 11: Is it important enough to dethrone Java 8?

To celebrate the release of Java 11, we invited nine Java experts to share their best & worst experiences with the latest version. Since this series is meant to be a manual on Java 11, our interviewees talked about their first impression of Java 11, the tips and tricks, the cleverest hacks and inevitably, if they really care about Java 11 -more than they cared about Java 8, at least.

The series is coming to an end but not before we ask our experts one last question: How much do you care about Java 11? This might sound weird so here’s some context: at last year’s JAX London, we talked to Stephen Colebourne about the (then) new release cadence and why people were still using Java 8. One year and two versions later (Java 9 was released one month before the interview), a lot of things have changed but we’re still asking the same question: is the latest version important enough to dethrone Java 8?

Java 8 will satisfy us for a good few years until there’s something really big and important.

Stephen Colebourne

Can Java 11 be that important version? We tried to answer this question two months ago but now that Java 11 is here, it’s time to revisit the question. If you’d like to see what our Java influencers think about the latest release, don’t miss this interview series. Just to give you an idea of what’s included, here’s a quote from one of the interviewees:

With Java 11 enforcing modularity, this will be the first real migration milestone for many projects. We now have a reasonable number of experiences about how to use the module system and how to migrate and build new software on top.

Markus Eisele

Meet the experts

Mala Gupta (@eMalaGupta) is the founder of eJavaGuru.com. She is a Java Champion, book author, speaker, and co-leader of DelhiJUG.

Josh Long (@starbuxman) is the Spring Developer Advocate at Pivotal. He is the author of 5 books and 3 best-selling video trainings. He is also a Java Champion.

Lukas Eder (@lukaseder) is the founder and head of R&D at Data Geekery GmbH, the company behind jOOQ and a Java Champion.

Matthew Gillard (@MaximumGilliard) works for Oracle in Bristol (UK) on Open-Source, Java and Serverless/Cloud infrastructure.

Marcus Biel (@MarcusBiel ) is a speaker, author, JCP member, and Java Clean Code Evangelist.

Trisha Gee (@trisha_gee ) is a Developer Advocate at JetBrains, a key member of the London Java Community and a Java Champion.

Simon Ritter (@speakjava ) is the Deputy CTO of Azul Systems.

Tal Weiss (@weisstal) is the CTO and co-founder of OverOps.

Stephen Colebourne (@jodastephen) is a Java Champion and JavaOne Rock Star speaker. He works as a developer at OpenGamma.

Do you care about Java 11?

Mala Gupta: JDK 11 is an important release – for all stakeholders.

JDK 11 marks a landmark move towards supporting Open Source Software by Oracle. With JDK 11, OracleJDK will be functionally equivalent to OpenJDK. For instance, features that previously existed only in OracleJDK, like ‘Flight Recorder’ are included in OpenJDK now.

JDK 11 is the next LTS (Long Term Support) release after Java 8. Most of the organizations are still running their applications on Java 8, fearing migration to Java 9 or 10, which were STS (Short Term Support) releases. With longer support from Oracle, many organizations are expected to migrate to JDK 11.

The introduction of newer Garbage collectors and memory management is encouraging organizations to further research and push development in this domain.

I rather appreciate how stable Java 11 is.

Josh Long: Java 8 was a landmark release that had a ton of huge features. Java 11 doesn’t quite reach that level of import but I don’t think that’s the goal, now that we’ve got bi-annual releases of Java. If you look at the language syntax and API goodies available in Java 9, 10, 11, and 12 (which will, among other things, support multiline strings), I still couldn’t argue it was as important as Java 8.

Instead, I rather appreciate how stable this release is. It’s got zero things that worry me, as a Spring developer, and lots of small things that’ll make my life in production easier. The Spring Initializr will support it. It’s a nice place to re-platform and I sincerely hope everyone does.

Lukas Eder: Not at all. JDK 9 – 11 haven’t been really interesting for me. As I mentioned before, due to the nature of my work on jOOQ, I mostly care about Java language features, not JVM or JDK features. Having said so, I do look forward to JDK 12 and JEP 325 and JEP 326 (yay!) very much!

Matthew Gillard: Yes, I do.  I think this is certainly a very important release. My experience from speaking to people at Java events is that hardly anyone has adopted 9 or 10 in production, but that many are looking to upgrade straight from 8 to 11. So the benefits which have been introduced in 9, 10 and 11 will get widespread use at last.  

In particular, there have been numerous improvements in how the JVM behaves in containers, as well as some nice language features – local variable type inference is probably the most notable – and core library improvements such as the new HTTP client which allows programmers a really modern programming style based on CompletableFutures.

Marcus Biel: Well, without doubt, it is a much smaller release than Java 8, but Java 11 is another consistent (baby) step in the right direction. JEP 181, for example, sets the course for future enhancements that will come with later Java releases.

When I have to go back to Java 8 now I miss all those little features introduced in Java 9, 10 and 11.

Trisha Gee: Yes, I would like to see teams/applications move from Java 8 to 11.  I’ve been using 9, 10 and now 11 for the last year (or more, as I was using an early access version of 9) and I’ve got used to the small conveniences: Factory Methods for Collections (Java 9); var (Java 10); Immutable Collections (Java 9, plus Collectors.toUnmodifiableList etc came in Java 10); and a few nice little methods on the Streams API and Optional just make some of the things that were introduced in 8 that bit easier to work with.  When I have to go back to Java 8 now I miss all those little features.

Simon Ritter: I do care about JDK 11 because it is the first new long-term support (LTS) release under the six-month release cadence.  I suspect that most Java users will migrate from JDK 8 to JDK 11 because Oracle and others like Azul and AdoptOpenJDK will provide extended support for this release.

SEE ALSO: “Developers will see Java 11 as a better, cleaner implementation of the features they use in Java 8”

Tal Weiss: Definitely. I am excited to see the new experimental ZGC implementation in action, promising low-latency garbage collection even for very large heaps. There are other new features that are interesting as well. On the flip side, I think that in terms of the magnitude of the release, Java 11 is much smaller than past releases like Java 8 or Java 9, but that’s a good thing.

Stephen Colebourne: Yes. Java 11 is an important release because it will be treated as being stable for the long term. It will receive security updates from Red Hat, IBM, Azul and others for many years via OpenJDK, just like Java 8 has.

If you’ve been holding off because of the difficulties of Java 9, the Java 11 release is the one to aim for. And remember that there is no need to modularise your code in order to move beyond Java 9!

 

Java 11 recap

Mistakes you’ve made while experimenting with Java 11

Trish Gee: Because of the changes in Java 11, some older versions of the libraries I was using weren’t working anymore.  I found problems with runtime errors of missing class files for example. There were two things which made my life easier – making sure I was using the most up-to-date versions of my dependencies; and adding additional dependencies for APIs that have moved out of the core libraries (in my case, JAXB).

Simon Ritter: Because of the relatively small number of developer features in JDK 11 nothing I’ve tried out has caused me any problems.  The documentation for the new features is very good, so all the things I’ve tried have worked on the first attempt.

 

Cleverest hacks discovered so far

Matthew Gillard: The single source file launcher with shebang line is super-neat – I use it with the new EpsilonGC for scripting use-cases:

 #!/opt/jdk/jdk-11/bin/java --source 11 -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC
	public class MyClass {
  	public static void main(String... args){
  	...

Tal Weiss: I really like the implementation of JEP 330, which allows for very fast prototyping of Java code using Shebang syntax via the command line, without needing to go through a build chain. I think it’s also very convenient for general-purpose scripting and for learning the language.

 

Pros & cons

Pros

+ using HTTP Client to work with non-blocking asynchronous code

+ using annotations with local variables for lambda parameters

+  the really quick turnaround integration of TLS 1.3

+ the new support for ChaCha20 and Poly1305 cryptographic algorithms

+ better startup performance than Java 9 and 10

String API enhancements (repeat, isBlank, strip, lines) are pretty cool

+ obsolete features are thrown overboard

+ smaller impact when upgrading

+ using the launch single-file source-code programs

+ the small change to the Predicate interface that adds the not() static method

Cons

– launching single source code programs without compilation is confusing

– has very little for programmers

– possible inconveniences for those users depending on the deprecated bits in this release

– JAXB has been removed from the JDK in JDK 11. It causes jOOQ users some extra trouble to configure when setting up jOOQ for the first time

– startup is still comparable to Java 8

 

17 features for Java 11

Just to freshen up your memory, JDK 11 includes the following features:

181: Nest-Based Access Control

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.

309: Dynamic Class-File Constants

Extend the Java class-file format to support a new constant-pool form, CONSTANT_Dynamic. Loading a CONSTANT_Dynamic will delegate creation to a bootstrap method, just as linking an invoke dynamic call site delegates linkage to a bootstrap method.

315: Improve Aarch64 Intrinsics

Improve the existing string and array intrinsics, and implement new intrinsics for the java.lang.Math sin, cos and log functions, on AArch64 processors.

318: Epsilon: A No-Op Garbage Collector

Develop a GC that handles memory allocation but does not implement any actual memory reclamation mechanism. Once the available Java heap is exhausted, the JVM will shut down.

320: Remove the Java EE and CORBA Modules

Remove the Java EE and CORBA modules from the Java SE Platform and the JDK. These modules were deprecated in Java SE 9 with the declared intent to remove them in a future release.

321: HTTP Client (Standard)

Standardize the incubated HTTP Client API introduced in JDK 9, via JEP 110, and updated in JDK 10.

323: Local-Variable Syntax for Lambda Parameters

Allow var to be used when declaring the formal parameters of implicitly typed lambda expressions.

324: Key Agreement with Curve25519 and Curve448

Implement key agreement using Curve25519 and Curve448 as described in RFC 7748.

327: Unicode 10

Upgrade existing platform APIs to support version 10.0 of the Unicode Standard.

328: Flight Recorder

Provide a low-overhead data collection framework for troubleshooting Java applications and the HotSpot JVM.

329: ChaCha20 and Poly1305 Cryptographic Algorithms

Implement the ChaCha20 and ChaCha20-Poly1305 ciphers as specified in RFC 7539. ChaCha20 is a relatively new stream cipher that can replace the older, insecure RC4 stream cipher.

330: Launch Single-File Source-Code Programs

Enhance the java launcher to run a program supplied as a single file of Java source code, including usage from within a script by means of “shebang” files and related techniques.

331: Low-Overhead Heap Profiling

Provide a low-overhead way of sampling Java heap allocations, accessible via JVMTI.

332: Transport Layer Security (TLS) 1.3

Implement version 1.3 of the Transport Layer Security (TLS) Protocol.

333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)

The Z Garbage Collector, also known as ZGC, is a scalable low-latency garbage collector.

335: Deprecate the Nashorn JavaScript Engine

Deprecate the Nashorn JavaScript script engine and APIs, and the jjs tool, with the intent to remove them in a future release.

336: Deprecate the Pack200 Tools and API

Deprecate the pack200 and unpack200 tools, and the Pack200 API in java.util.jar.

Author
Gabriela Motroc
Gabriela Motroc is editor of JAXenter.com and JAX Magazine. Before working at Software & Support Media Group, she studied International Communication Management at the Hague University of Applied Sciences.