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

Manual on Java 11: Cleverest hacks to simplify your Java 11 navigation

Gabriela Motroc
Java 11
© Shutterstock / gguy

New Java release, new series! This time, we invited eight Java experts to share their best and worst experiences with Java 11, the hacks they discovered so far, their tips & tricks and more. By the time we’re done with all the parts of this series, it should look like a manual on Java 11.

Java 11: Tips & tricks, everyday pitfalls & more

To celebrate the release of Java 11, we invited eight 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 will also talk 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.

But first, some context: Before Java 11 was released, we talked to eight Java influencers about the migration to the latest version and whether it’s a “worthy” migration milestone even if it doesn’t have “killer feature to drive adoption,” as Martin Thompson opined in the interview series. If you haven’t migrated yet, we thought you’d like to know the pros and cons of this new version.

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

Don’t miss the first parts of our “Manual on Java 11” series:

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.

Tips & tricks to better “navigate” Java 11

Mala Gupta: The following steps refer to OpenJDK and not OracleJDK. That being said,  I prefer to start with the ‘features’ link here.

The features tab opens a list of JEP (Java Enhancement Proposal) numbers and their name:

The details of each JEP includes its ‘scope’ and ‘component’:

I prefer to navigate the features of a new Java release, by grouping the JEPs on their scope and further sub-grouping them on their component types. In Java 11, the scope of the JEPs are categorized into ‘Implementation’, ‘JDK’ and ‘SE’. After an overview, I deep dive:

JEPs (Scope: Implementation)

The garbage collectors – Epsilon, ZGC; and Aarch64 Intrinsics specify the requirements. To use them, they should be implemented by a SE implementation.

Within a scope, a JEP could be further sub-grouped on the type ‘Component’. For example, the garbage collectors Epsilon and ZGC deal with the gc in Hotspot. Aarch64 Intrinsics deals with compiler in hotspot.

JEPs (Scope: JDK)

Launching Single-File Source-Code Programs modifies how the compiler – a JDK tool, adds launching of a class from a source file (without explicit compilation). Deprecation of the Nashorn JavaScript Engine affects the core-libs in JDK. The Flight Recorder and Low-Overhead Heap Profiling is part of the hotspot VM.

JEPs (Scope: SE)

All the preceding JEPs are related to the SE. The Local-variable Syntax for Lambda parameters aligns the usage of ‘var’ with the lambda parameters. With ‘var’, you can also use annotations with the lambda parameters.

Pack200 compression scheme was used with the jar files or applets around Java 5, to reduce the size of Java’s application packages, so they could be downloaded over the internet. With the increased internet speed and deprecation of applets, Pack200 is rendered redundant, marking it deprecated.

Classes defined in same source file are compiled to different bytecode files, resulting in the broadening of scope of private members to package, usually with bridge methods. Nest-based access control introduce the formal concept of multiple classes forming a nest, when defined in the same source file, sharing a common access control mechanism.

HTTP Client and Unicode 10, affect core libraries – java.net and java.lang respectively.

Removal of the Java EE and CORBA Modules (since Java EE is now with Eclipse Foundation),

Key Agreement with Curve25519 and Curve448, ChaCha20 and Poly1305 Cryptographic Algorithms and Transport Layer Security (TLS) 1.3 deal with the changes in the security libraries.

Accessing the list of minor modifications

Scroll the page that opens by clicking the link ‘Release Notes’ on the previous page. Scroll down to view the additions or modifications, which are not part of a JEP:

Accessing the annotated API Specification

It enables you to view all changes in the Java API – additions, modifications or deletions. For example, lets walk through the required steps to access the modified Java String API specs.

Step 2: Click ‘Annotated API Specification’

Step 3: Preceding step takes you to a page which lists all Java API changes from Java 10.

Step 4: Scroll the page and click on java.lang

Step 5: Click on String (left panel) on the page that opens after clicking java.lang.

Step 6: The String class lists the addition of 6 new methods (in green color).

Step 7: View the newly added methods to the String class in the left panel. Access the method description in the right panel.

Josh Long: The JDK is itself pretty straightforward. It’s the licensing that can be tricky! Fellow Java Champion Simon Ritter released a nice post on the options for those considering which build of the JDK to use. Then, even more recently we Java Champions released a document – Java is Still Free – clarifying as much as we can. I heartily recommend readers read both documents.

Matthew Gillard: I’ve found that the JEPs (JDK Enhancement Proposals) here are really readable and provide a lot of rationale for new features. Beyond that – read the JavaDoc, read the blogs, and play around – try stuff out!

Marcus Biel: First port of call is certainly the OpenJDK project page, where the 17 JEPs of the Java 11 release are listed. At first glance, Java 11 seems to offer mainly changes “under the hood” and no real developer features. However, this isn’t the case.

The String API enhancements (repeat, isBlank, strip, lines) for example, I think are pretty cool. For me, it’s often the little things that make our lives as developers easier. Up until now, we’ve had to access an external library like commons-lang for such simple things like “isBlank” – great that we can save that in the future! Last, but not least, I think it’s always good when obsolete features are thrown overboard – like the Java EE and CORBA modules or Java Web Start.

At first glance, Java 11 seems to offer mainly changes “under the hood” and no real developer features. However, this isn’t the case.

Trisha Gee: JDK 11 actually removes some APIs, which will probably be the biggest surprise for many.  For example, CORBA is gone, the Java EE code is no longer in the SE code (you should be using external Java EE libraries), and JavaFX is now an external dependency and is being maintained as a community effort.

Simon Ritter: There are a couple of resources I would point developers at, aside from my blog post, of course.

For a list of new APIs since JDK 10, Gunnar Morling’s list on Github is very useful.  This can be used in conjunction with the standard API documentation to learn about all the new classes and methods available in JDK 11.

Also, to see what -XX command line options for the java command have changed, Chris Newland has produced an excellent resource.

Tal Weiss: The official JDK 11 page on the OpenJDK website has a very clear release notes page, with links to the different JEPs incorporated into the release. The JEPs are very well written, including clear descriptions, goals, and implementation notes. This alone is enough in my opinion to navigate JDK 11.

 

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.

 

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.

 

In the last part of this mini-series, experts will reveal whether they really care about Java 11 -more than they cared about Java 8, at least. Why is this important? You’ll find out soon!

asap

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.