Nearby lessons

118 of 125

Java 14 Features

📌 What You Will Learn
  • Switch expressions — now FINAL
  • Records — the compact class (preview)
  • Pattern matching for instanceof (preview)
  • Helpful NullPointerException messages
  • Text blocks second preview

Java 14 Features is a core concept of the Java language. This lesson explains Java 14 — Big Ideas Begin, Helpful NullPointerException Messages and Beyond Java 14 — What Comes Next (Your Roadmap) with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.

Java 14 — Big Ideas Begin

Java 14 (March 2020) is the last version covered in the classic training material this book is based on. It finalized switch expressions and showed two preview features that will change how we write Java: Records and Pattern matching for instanceof. Both became final in Java 16.

Helpful NullPointerException Messages

Before Java 14, a NullPointerException was a mystery: just Exception in thread main java.lang.NullPointerException with no clue where.

In simple words: The helpful NPE message tells you exactly which call failed and what was null. Instead of guessing, the JVM names the method that was invoked on null and the value that returned null.

The JVM now tells you exactly which method returned null and where the failure happened. Enable this by default since Java 15 (from Java 14, you could opt in with -XX:+ShowCodeDetailsInExceptionMessages).

Example02
JCode Cell
1// Old NPE message (unhelpful)
2java.lang.NullPointerException
3 
4// Java 14+ helpful NPE message
5java.lang.NullPointerException: Cannot invoke
6"Student.getName()" because the return value of
7"Test.getStudent()" is null

Beyond Java 14 — What Comes Next (Your Roadmap)

This material's classic book ends at Java 14. As your 20+ years experienced trainer, here is the honest roadmap of what came after — so you are never outdated:

VersionHeadline features
Java 15Text blocks FINAL, ZGC final, sealed classes preview
Java 16Records FINAL, pattern matching for instanceof FINAL
Java 17 (LTS)Sealed classes FINAL, strong encapsulation, long-term support
Java 18-20Small releases; simple web server, virtual threads preview
Java 21 (LTS)Virtual threads, switch patterns, record patterns, String templates preview
Java 22-24String templates, structured concurrency previews, newer LTS cadence
Trainer's Note: Trainer's final advice: the concepts in this entire material — from Chapter 1 to 31 — are the rock-solid foundation. Java 8 features and the modern ideas shown in Chapters 25-31 are what companies use daily. After this book, the natural next steps are: JDBC + a database, Servlets/Spring Boot, and building real projects. Keep practising one program every day, and you will master Java.
📝 Key Takeaways
  • Switch expressions became FINAL in Java 14.
  • Records create data classes with automatic constructor, getters, toString, equals, hashCode.
  • Pattern matching for instanceof combines check and cast into one step.
  • Helpful NPE messages tell you exactly which value was null.
  • Text blocks got a second preview before becoming final in Java 15.
  • After Java 14: Java 15-24 added text blocks, records, sealed classes, virtual threads.

🧠 Test Your Knowledge

2 Questions
Progress: 0 / 2