
Top 50 Java 9 to Java 17 Interview Questions and Answers
Jul 16, 2025 5 Min Read 453 Views
(Last Updated)
Java has undergone a remarkable transformation from version 9 to 17, introducing a wide range of features that enhance performance, simplify syntax, and modernize the development experience. From the revolutionary Java Platform Module System (JPMS) in Java 9 to the finalization of Pattern Matching and Sealed Classes in Java 17, each version brought something powerful to the table. And you must master it, if you’d like to land a top job.
This guide compiles the top 50 Java 9 to Java 17 interview questions—complete with answers and examples—to help you master key concepts quickly. Covering core language enhancements, new APIs, and syntactic sugar, this resource will sharpen your understanding and prepare you to confidently tackle real-world interview scenarios. Let’s begin!
Table of contents
- Java 9 to 11 Interview Questions (Part 1)
- What are the key features introduced in Java 9?
- What is JPMS (Java Platform Module System)?
- What is JShell in Java 9?
- What are private methods in interfaces in Java 9?
- What improvements were made to the Stream API in Java 9?
- How does try-with-resources work in Java 9?
- What is 'var' introduced in Java 10?
- Can 'var' be used in method parameters or return types?
- What is the benefit of the 'var' keyword?
- What is the Garbage Collector (GC) improvement in Java 10?
- What is application class-data sharing (AppCDS) in Java 10?
- What is the new optional API method in Java 10?
- What are the major features of Java 11?
- Explain the new String methods added in Java 11.
- What is the new HTTP Client API in Java 11?
- What is the 'var' support for lambda parameters in Java 11?
- What is the deprecation of Nashorn in Java 11?
- What is the purpose of stripLeading() and stripTrailing() in Java 11?
- How does String.repeat(int) work in Java 11?
- What are the file read enhancements in Java 11?
- Java 12 to 14 Interview Questions (Part 2)
- What are switch expressions introduced in Java 12?
- What is the new method indent() in Java 12?
- What is the new transform() method in Java 12?
- What is the TeX-style Number Formatting introduced in Java 12?
- What is JVM constant API (Java 12)?
- What is JEP 355 - Text Blocks (Preview in Java 13)?
- What improvements were made to Switch Expressions in Java 13?
- What is the Legacy Socket API replacement in Java 13?
- What is JEP 358: Helpful NullPointerExceptions (Java 14)?
- What is Records (preview feature in Java 14)?
- What is Pattern Matching for instanceof (Preview in Java 14)?
- What is the benefit of Records over traditional classes?
- Can Records be extended in Java?
- What is the yield keyword used for in Java?
- What is the difference between Text Blocks and traditional strings?
- Can you use methods inside Records?
- What happens if you add a mutable field to a Record?
- What is the default access modifier for Record fields?
- How are equals() and hashCode() implemented in Records?
- What annotation is implicitly applied to Record classes?
- Java 15 to Java 17 Interview Questions (Part 3)
- What is the Sealed Classes feature introduced in Java 15?
- What is the benefit of Sealed Classes?
- What are Hidden Classes introduced in Java 15?
- What is JEP 360 - Text Blocks standardization in Java 15?
- What is the difference between Records and Sealed Classes?
- What is Pattern Matching for instanceof finalized in Java 16?
- What is JEP 394: Pattern Matching for instanceof?
- What is the new Packaging Tool (jpackage) in Java 16?
- What is the context of Strong Encapsulation in Java 16 and 17?
- What are the finalized features in Java 17 (LTS)?
- Concluding Thoughts…
Java 9 to 11 Interview Questions (Part 1)
Java 9 to 11 introduced major enhancements like the Java Platform Module System (JPMS), JShell, and the modern HTTP Client API. This section focuses on foundational upgrades that shaped Java’s transition to modularity and developer-friendly tools.
1. What are the key features introduced in Java 9?
Answer:
Java 9 introduced the Java Platform Module System (JPMS), JShell (REPL), private methods in interfaces, improved Stream API, and better resource management in try-with-resources.
Example:
try (BufferedReader br = new BufferedReader(new FileReader(“file.txt”))) { // auto-close works } |
2. What is JPMS (Java Platform Module System)?
Answer:
JPMS allows developers to modularize Java applications, enabling better encapsulation, faster startup, and scalable systems.
Example:
module com.example.module { requires java.base; exports com.example.api; } |
3. What is JShell in Java 9?
Answer:
JShell is a REPL (Read-Eval-Print Loop) tool to run Java statements and expressions interactively.
Example:
jshell> int a = 10 a ==> 10 |
4. What are private methods in interfaces in Java 9?
Answer:
You can declare private methods inside interfaces to reuse common logic between default or static methods.
Example:
interface Demo { private void log(String msg) { System.out.println(msg); } } |
5. What improvements were made to the Stream API in Java 9?
Answer:
Methods like takeWhile(), dropWhile(), and ofNullable() were added.
Example:
List<Integer> list = List.of(1, 2, 3, 4, 5); list.stream().takeWhile(x -> x < 4).forEach(System.out::println); // 1 2 3 |
6. How does try-with-resources work in Java 9?
Answer:
You can use variables declared outside the try block if they are final or effectively final.
Example:
BufferedReader br = new BufferedReader(new FileReader(“data.txt”)); try (br) { System.out.println(br.readLine()); } |
7. What is ‘var’ introduced in Java 10?
Answer:
Java 10 introduced local variable type inference using var. It’s only for local variables, and the type is inferred at compile-time.
Example:
var name = “Java”; // inferred as String |
8. Can ‘var’ be used in method parameters or return types?
Answer:
No, var can only be used for local variables inside methods, constructors, and initialization blocks.
9. What is the benefit of the ‘var’ keyword?
Answer:
It reduces verbosity and improves readability without sacrificing type safety.
10. What is the Garbage Collector (GC) improvement in Java 10?
Answer:
Java 10 introduced the G1 GC parallel full garbage collection, improving pause times and performance.
11. What is application class-data sharing (AppCDS) in Java 10?
Answer:
AppCDS allows class metadata to be shared across JVMs to reduce startup time and memory usage.
12. What is the new optional API method in Java 10?
Answer:
Optional.orElseThrow() without arguments behaves like get() but with clearer semantics.
Example:
Optional<String> opt = Optional.of(“Java”); String value = opt.orElseThrow(); // returns “Java” |
13. What are the major features of Java 11?
Answer:
Java 11 introduced the HTTP Client API, Local-Variable Syntax for Lambda Parameters, and String utility methods like isBlank(), lines(), strip(), etc.
14. Explain the new String methods added in Java 11.
Answer:
- isBlank(): checks if a string is empty or whitespace.
- lines(): splits string into lines.
- strip(): trims whitespaces using Unicode.
Example:
System.out.println(” Java “.strip()); // “Java” System.out.println(“”.isBlank()); // true |
15. What is the new HTTP Client API in Java 11?
Answer:
A modern replacement for HttpURLConnection, supporting synchronous and asynchronous requests.
Example:
HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(“https://example.com”)) .build(); HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); |
16. What is the ‘var’ support for lambda parameters in Java 11?
Answer:
You can now use var in lambda parameters, which allows annotations and improved clarity.
Example:
list.forEach((var item) -> System.out.println(item)); |
17. What is the deprecation of Nashorn in Java 11?
Answer:
The Nashorn JavaScript engine was deprecated due to lack of ECMAScript support and alternatives like GraalVM.
18. What is the purpose of stripLeading() and stripTrailing() in Java 11?
Answer:
They remove whitespaces from the beginning or end of strings using Unicode-aware logic.
Example:
System.out.println(” Java”.stripLeading()); // “Java” |
19. How does String.repeat(int) work in Java 11?
Answer:
Repeats a string n times.
Example:
System.out.println(” Java”.stripLeading()); // “Java” |
20. What are the file read enhancements in Java 11?
Answer:
Files.readString(Path) and Files.writeString(Path, String) simplify reading and writing files.
Example:
Path path = Path.of(“file.txt”); String content = Files.readString(path) |
Java 12 to 14 Interview Questions (Part 2)
With Java 12 to 14, the language became more expressive and concise. Features like switch expressions, text blocks (preview), compact number formatting, and Records laid the groundwork for cleaner, more readable code in enterprise applications.
21. What are switch expressions introduced in Java 12?
Answer:
Switch expressions return a value and support new -> syntax, making the code concise.
Example:
int day = 3; String result = switch (day) { case 1, 2 -> “Start”; case 3 -> “Mid”; default -> “End”; }; System.out.println(result); // Mid |
22. What is the new method indent() in Java 12?
Answer:
Adds or removes spaces in each line of a string.
Example:
String text = “Java\nRocks”; System.out.println(text.indent(4)); |
23. What is the new transform() method in Java 12?
Answer:
Allows chaining string operations using lambda expressions.
Example:
String result = “java”.transform(s -> s.toUpperCase()); System.out.println(result); // JAVA |
24. What is the TeX-style Number Formatting introduced in Java 12?
Answer:
The new CompactNumberFormat formats numbers like 1,000 -> 1K.
Example:
NumberFormat nf = NumberFormat.getCompactNumberInstance(Locale.US, NumberFormat.Style.SHORT); nf.setMaximumFractionDigits(1); System.out.println(nf.format(1000)); // 1K |
25. What is JVM constant API (Java 12)?
Answer:
New APIs added to java.lang.constant package to model class file constants.
26. What is JEP 355 – Text Blocks (Preview in Java 13)?
Answer:
Text Blocks allow multi-line strings using “””, making JSON/HTML/XML easier to write.
Example:
String html = “”” <html> <body>Java 13</body> </html> “””; |
27. What improvements were made to Switch Expressions in Java 13?
Answer:
Added yield keyword to return values from block-style cases.
Example:
int value = switch (day) { case 1 -> 10; case 2 -> 20; default -> { yield 30; } }; |
28. What is the Legacy Socket API replacement in Java 13?
Answer:
JEP 353 replaced the legacy SocketImpl with a more maintainable and scalable implementation.
29. What is JEP 358: Helpful NullPointerExceptions (Java 14)?
Answer:
Provides more context in NullPointerException, like which variable was null.
Example:
// With -XX:+ShowCodeDetailsInExceptionMessages obj.getData().toLowerCase(); // will indicate obj was null |
30. What is Records (preview feature in Java 14)?
Answer:
Records are immutable data classes with less boilerplate code.
Example:
record Person(String name, int age) {} Person p = new Person(“Alice”, 30); System.out.println(p.name()); // Alice |
31. What is Pattern Matching for instanceof (Preview in Java 14)?
Answer: Simplifies type casting after instanceof check.
Example:
if (obj instanceof String s) { System.out.println(s.toUpperCase()); } |
32. What is the benefit of Records over traditional classes?
Answer:
Records auto-generate getters, equals(), hashCode(), and toString(), reducing boilerplate.
33. Can Records be extended in Java?
Answer:
No, Records are implicitly final and cannot extend other classes.
34. What is the yield keyword used for in Java?
Answer:
Used in switch block cases to return a value.
Example:
int result = switch (x) { case 1 -> 10; default -> { yield 100; } }; |
35. What is the difference between Text Blocks and traditional strings?
Answer:
Text blocks allow multi-line, readable formatting, avoiding escape sequences.
Example:
String json = “”” { “name”: “Java” } “””; |
36. Can you use methods inside Records?
Answer:
Yes, Records can have methods and static fields.
Example:
record User(String name) { public String greet() { return “Hello ” + name; } } |
37. What happens if you add a mutable field to a Record?
Answer:
You can add it, but it’s discouraged since Records are meant to be immutable.
38. What is the default access modifier for Record fields?
Answer:
Fields are private and final by default, with public accessor methods auto-generated.
39. How are equals() and hashCode() implemented in Records?
Answer:
Auto-generated based on all fields defined in the record header.
40. What annotation is implicitly applied to Record classes?
Answer:
@java.lang.Record (marker type). Also considered implicitly final.
Java 15 to Java 17 Interview Questions (Part 3)
Java 15 to 17 finalized some of the most awaited features, such as Sealed Classes, Pattern Matching, and native packaging tools. These additions emphasize strong encapsulation, improved security, and better code maintainability, especially crucial for modern Java development.
41. What is the Sealed Classes feature introduced in Java 15?
Answer:
Sealed classes restrict which other classes or interfaces can extend or implement them, improving control and modeling hierarchies.
Example:
public sealed class Shape permits Circle, Rectangle {} final class Circle extends Shape {} final class Rectangle extends Shape {} |
42. What is the benefit of Sealed Classes?
Answer:
Improved security and better modeling of domain constraints by explicitly controlling subclassing.
43. What are Hidden Classes introduced in Java 15?
Answer:
Classes are intended for use by frameworks that generate classes at runtime. They cannot be used directly by the bytecode of other classes.
44. What is JEP 360 – Text Blocks standardization in Java 15?
Answer:
Text Blocks became a standard feature after being previewed in earlier versions.
Example:
String html = “”” <html> <body>Hello</body> </html> “””; |
45. What is the difference between Records and Sealed Classes?
Answer:
- Records: for data-carrying classes (immutable).
- Sealed Classes: restrict inheritance for class hierarchy modeling.
46. What is Pattern Matching for instanceof finalized in Java 16?
Answer:
The preview feature from Java 14 became permanent in Java 16, allowing simplified casting.
Example:
if (obj instanceof String s) { System.out.println(s.length()); } |
47. What is JEP 394: Pattern Matching for instanceof?
Answer:
It eliminates the need for casting after instanceof, reducing boilerplate.
48. What is the new Packaging Tool (jpackage) in Java 16?
Answer:
Jpackage allows packaging Java applications as native installers (MSI, DMG, etc.).
Example:
jpackage –name MyApp –input out/ –main-jar app.jar
49. What is the context of Strong Encapsulation in Java 16 and 17?
Answer:
Internal APIs (sun.*) are strongly encapsulated by default; access via reflection is restricted.
50. What are the finalized features in Java 17 (LTS)?
Answer:
Java 17 finalized many preview features:
- Sealed Classes
- Pattern Matching
- Enhanced Pseudo-Random Number Generator API
- Foreign Function & Memory API (Incubator)
- Strong encapsulation of internal APIs
Example – Sealed Class in Java 17:
public sealed interface Vehicle permits Car, Bike {} final class Car implements Vehicle {} final class Bike implements Vehicle {} |
Looking to build a solid foundation in Java and land high-paying full-stack roles?
Check out GUVI’s Java Full Stack Development Course, co-certified by IIT-Madras. This industry-aligned program covers everything from core Java to Spring Boot, frontend, databases, and project deployment, making you job-ready with hands-on experience.
Concluding Thoughts…
Java’s steady evolution from version 9 to 17 reflects its commitment to modern software development needs, introducing everything from local variable inference to more expressive switch constructs and powerful class modeling tools. This guide is going to be your saviour if you’re preparing for product-based interviews, certification exams, or upskilling for new projects. These 50 curated questions give you both depth and practical clarity.
By revisiting and practicing these essential features, you not only strengthen your Java fundamentals but also demonstrate your readiness to work with up-to-date codebases. Java 17, being a Long-Term Support (LTS) release, marks a stable foundation for years to come, so make sure you’re fully equipped with the knowledge it brings. Good Luck!
Did you enjoy this article?