Java 17 and 21 Features Interview Questions

Most companies have moved from Java 8 to Java 17 or 21, and Spring Boot 3 requires Java 17, so interviewers now expect you to know modern Java. This topic covers the features asked about most: var, records and compact constructors, sealed classes, switch expressions, pattern matching for instanceof and switch, record patterns, text blocks, sequenced collections, and the new String, Stream and Optional methods.

It finishes with virtual threads from Java 21: how they differ from platform threads, how to use them in Spring Boot, and when not to use them. Every answer includes a complete program you can run on Java 21, with its real output.