Finalized in Java 17 (JEP 409). This is the headline language feature of the Java 17 LTS release. Previous previews: Java 15 (JEP 360) and Java 16 (JEP 397). The Problem: Open Hierarchies Are Hard to Reason About In Java, any class can be extended by default. This openness is flexible but has costs. Consider a Shape interface used in a drawing application: // Java 11 — anyone can implement Shape public interface Shape { double area(); } At runtime, a Shape instance could be a Circle, a Rectangle, a Triangle, or anything else in the classpath.
Continue reading »Java 17 Tutorial
14 posts in this section
Setting Up Java 17: JDK Options, Tooling, and IDE Configuration
JDK Distribution Options Multiple vendors ship Java 17 JDK builds. All pass the TCK (Technology Compatibility Kit) — they are functionally equivalent for development. Distribution Provider Notes Eclipse Temurin Adoptium / Eclipse Recommended default; fully open-source Amazon Corretto AWS Free; optimized for AWS Lambda and EC2 Microsoft Build of OpenJDK Microsoft Windows and Azure optimized Oracle JDK 17 Oracle Free for development; commercial license for production Azul Zulu Azul Commercial support available; free binaries GraalVM CE 22.
Continue reading »Switch Expressions (JEP 361): Switch as an Expression, Not Just a Statement
Finalized in Java 14 (JEP 361). Available in all Java 14+ releases, including Java 17. Previous previews: Java 12 (JEP 325) and Java 13 (JEP 354). The Problem with Switch Statements Java’s traditional switch statement has two well-known pain points: Pain 1: Fall-Through // Java 11 — easy to introduce fall-through bugs switch (day) { case MONDAY: result = "Start of work week"; break; // easy to forget this case TUESDAY: result = "Weekday"; // no break — falls through to WEDNESDAY case case WEDNESDAY: result = "Hump day"; break; default: result = "Other"; } A missing break causes the next case to execute unexpectedly.
Continue reading »Text Blocks (JEP 378): Multiline Strings Without the Escape Hell
Finalized in Java 15 (JEP 378). Available in all Java 15+ releases, including Java 17. Previous previews: Java 13 (JEP 355) and Java 14 (JEP 368). The Problem: Embedded Strings in Java Writing multi-line strings in Java has always been painful: // JSON — a wall of escape sequences and concatenation String json = "{\n" + " \"name\": \"Alice\",\n" + " \"role\": \"engineer\",\n" + " \"active\": true\n" + "}"; // SQL — unreadable indentation and newlines String sql = "SELECT u.
Continue reading »