Fundamentals 12 min read

Master Java 9‑16: Essential New Features You Must Know

This article quickly walks through the major new features introduced in Java versions 9 to 16—including private interface methods, var type inference, enhanced switch expressions, records, sealed classes, and new garbage collectors—helping developers stay up‑to‑date with the language’s rapid evolution.

Java Interview Crash Guide
Java Interview Crash Guide
Java Interview Crash Guide
Master Java 9‑16: Essential New Features You Must Know

Java's release pace has accelerated; since Java 8 introduced Lambda and Stream, new versions appear roughly every six months, leaving many projects still on Java 8 or 7 while new features keep emerging.

Understanding each version's main features is crucial to avoid being caught off‑guard when upgrading.

Java 9 (Sept 2017)

Private methods in interfaces

Java 9 allows private methods inside interfaces, which can be called from default methods, enabling code reuse without exposing the methods.

public interface TestInterface {
    default void wrapMethod() {
        innerMethod();
    }
    private void innerMethod() {
        System.out.println("");
    }
}

Anonymous inner classes support diamond operator

Java 9 adds diamond ( <>) support for anonymous inner classes.

List<Integer> numbers = new ArrayList<>();
List<Integer> numbers = new ArrayList<>() {
    ...
};

Enhanced try‑with‑resources

Resources declared outside the try block can now be automatically closed.

BufferedReader br0 = new BufferedReader(...);
BufferedReader br1 = new BufferedReader(...);
try (br0; br1) {
    System.out.println(br0.readLine() + br1.readLine());
}

Java 10 (Mar 2018)

Local variable type inference (var)

Java 10 introduces var for implicit type inference of local variables.

var message = "Hello, Java 10";

Java 11 (Sept 2018)

var in lambda parameters

Java 11 permits var in lambda parameters, allowing annotations.

List<String> languages = Arrays.asList("Java", "Groovy");
String language = sampleList.stream()
    .map((@Nonnull var x) -> x.toUpperCase())
    .collect(Collectors.joining(", "));
assertThat(language).isEqualTo("Java, Groovy");

Single‑file source‑code execution

Run a Java file directly with the java command.

$ java HelloWorld.java
Hello Java 11!

Java Flight Recorder open‑sourced

JFR is now part of OpenJDK, providing powerful profiling capabilities.

Java 12 (Mar 2019)

Switch expression

Switch statements become expressions with arrow syntax and can return values.

typeOfDay = switch (dayOfWeek) {
    case MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY -> "Working Day";
    case SATURDAY, SUNDAY -> "Day Off";
};

Pattern matching for instanceof

Instanceof now performs a cast automatically.

Object obj = "Hello Java 12!";
if (obj instanceof String str) {
    int length = str.length();
}

Java 13 (Sept 2019)

Switch with yield

Switch can contain a block and use yield to return a value.

typeOfDay = switch (dayOfWeek) {
    case MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY -> {
        // do sth...
        yield "Working Day";
    }
    case SATURDAY, SUNDAY -> "Day Off";
};

Text blocks

Multi‑line string literals are now supported via text blocks.

String json = """
{
    "id":1697301681936888,
    "nickname":"空无",
    "homepage":"https://juejin.cn/user/1697301681936888"
}
""" ;

Java 14 (Mar 2020)

Records

Compact data classes can be declared with record.

public record UserDTO(String id, String nickname, String homepage) { }

Improved NullPointerException messages

Stack traces now indicate which variable was null, making debugging easier.

Foreign‑memory access API

Safe APIs for off‑heap memory replace the unsafe operations.

jpackage tool

Package Java applications as native installers without requiring a separate JRE.

Java 15 (Sept 2020)

ZGC and Shenandoah GC

Both low‑pause garbage collectors become production‑ready.

Sealed classes

Classes can restrict which subclasses may extend them.

public sealed interface Service permits Car, Truck { }

Java 16 (Mar 2021)

No major user‑visible changes beyond the previous experimental features.

Summary

These new features illustrate Java’s rapid evolution; learning them early helps stay productive and avoid being left behind.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Javaprogramminglanguage featuresJava versions
Java Interview Crash Guide
Written by

Java Interview Crash Guide

Dedicated to sharing Java interview Q&A; follow and reply "java" to receive a free premium Java interview guide.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.