Ever since I tried my hands at the Java 25th year anniversary Oracle SE 11 Certification, I wanted to start by listing the features that I like best (or actually just use with intent) and which version (> 8) of Java is associated to those.
Java 9: An Unfortunate Feature Naming
Am referring to…
- Java 9 - Java Platform Module System,
- Though rather controversial, modularization serves strong encapsulation and associated to
jlinkis associated to reduced-size distributable runtime applications.
- Java 9 - private interface method
defaulthas been a great addition to Java 8, being able to share logic between default methods prevents code duplication which is always great!
jshell a bit gimmick-y but that probably is because I am used to shells in general.
- Java 10 -
- Inferring the type of local variables has the following most obvious benefit:
// Before VeryLongOrSubjectToChangeClassName variableName = new VeryLongOrSubjectToChangeClassName(...); // After var iAmSuchAVeryLongVariableName = new VeryLongOrSubjectToChangeClassName(...);
… but that can lead to funky scenarios such as anonymous class tricks, see https://nipafx.dev/java-var-anonymous-classes-tricks/.
- Java 11 - Extending
varto Lambda Parameters
- The declaration of the type for lambda parameters is only needed in some scenarios but in those you can now use the
// Before import java.awt.*; import java.awt.event.*; ... Button button = new Button("Click me!"); // Before (yes, you need parentheses) button.addActionListener((final ActionEvent actionEvent) -> ...); // After button.addActionListener((final var actionEvent) -> ...);
Want to read further?
See https://www.marcobehler.com/guides/a-guide-to-java-versions-and-features, https://dzone.com/articles/a-guide-to-java-versions-and-features or https://en.wikipedia.org/wiki/Java_version_history for instance.