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 through 16—including private interface methods, var type inference, enhanced switch expressions, records, sealed classes, and new garbage collectors—helping developers stay current and write cleaner, more efficient code.

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, with Java 8 introducing lambdas and streams, and subsequent versions arriving every six months.

Many projects still run on Java 8 or even Java 7, making it hard to keep up, but understanding each new version's key features is essential.

Java 9 (September 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 operator support for anonymous inner classes.

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

Enhanced try‑with‑resources

Java 9 lets resources be declared outside the try block, simplifying multiple resource management.

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

Java 10 (March 2018)

Local‑variable type inference (var)

The var keyword infers the type of local variables, reducing boilerplate.

var message = "Hello, Java 10";

Java 11 (September 2018)

var in lambda parameters

Lambda parameters can now use var, allowing annotations on inferred types.

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

Single‑file source‑code execution

Java 11 enables running a source file directly with the java command.

$ java HelloWorld.java
Hello Java 11!

Java Flight Recorder open‑sourced

JFR is now part of OpenJDK, providing a powerful diagnostic tool.

Java 12 (March 2019)

Compact switch expressions

Switch can now return values and use comma‑separated case labels.

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

Pattern matching for instanceof

Instanceof now combines type check and cast.

if (obj instanceof String str) {
    int length = str.length();
}

Java 13 (September 2019)

Switch enhancements with yield

Switch can now contain blocks 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 supported via text blocks.

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

Java 14 (March 2020)

Records

Records provide a compact syntax for data‑carrier classes.

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 replace Unsafe for off‑heap memory operations.

MemorySegment segment = MemorySegment.allocateNative(200);
VarHandle varHandle = MemoryHandles.varHandle(long.class, ByteOrder.nativeOrder());
varHandle.set(address, value);
segment.close();

jpackage tool

jpackage bundles Java applications into native installers.

Java 15 (September 2020)

ZGC and Shenandoah GC

Both low‑pause garbage collectors become production‑ready.

Sealed classes

Sealed classes restrict which other classes may extend or implement them.

public sealed interface Service permits Car, Truck {
    int getMaxServiceIntervalInMonths();
    default int getMaxDistanceBetweenServicesInKilometers() { return 100000; }
}

Java 16 (March 2021)

Java 16 consolidates earlier experimental features without major new changes.

Summary

The listed features illustrate Java’s rapid evolution; staying up‑to‑date lets developers leverage new syntax, performance improvements, and tooling.

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.

javaNew Featureslanguage updatesVersion 9-16
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.