Nearby lessons
114 of 125Java 9 Features
- JShell — the interactive Java playground
- Modules (JPMS) — the big architecture change
- Private methods in interfaces
- Factory methods for collections: List.of, Set.of, Map.of
- The updated try-with-resources
Java 9 Features is a core concept of the Java language. This lesson explains Java 9 — The Big Version, Java 8 vs Java 9 — Quick Comparison and Private Methods in Interfaces with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
Java 9 — The Big Version
Java 9 (September 2017) brought the largest change to the platform's structure: modules. It also gave us JShell, which made learning Java much more fun, plus many small daily-use improvements.
Java 8 vs Java 9 — Quick Comparison
| Point | Java 8 (2014) | Java 9 (2017) |
|---|---|---|
| Headline feature | Lambda + Stream API | Modules (JPMS) + JShell |
| Interfaces | Default and static methods | Also private methods |
| Collections | Arrays.asList(...) | List.of / Set.of / Map.of (immutable) |
| try-with-resources | Variables inside try brackets | Existing variables allowed |
| Learning tool | Command line only | JShell interactive playground |
Private Methods in Interfaces
Java 8 gave interfaces default and static methods. Java 9 lets interfaces also have private methods — hidden helper methods that default methods can share inside the interface.
Try-with-Resources Improvement
In Java 7, the resource variable had to be declared inside the try brackets. Java 9 lets us use variables already declared outside:
More Small Java 9 Additions
- String.chars() — a stream of the characters of a String.
- Optional.stream() — turns Optional into a stream.
- Stream.ofNullable() — safe stream of a possibly-null value.
- Stream.iterate(...) enhancements for creating streams.
- List.of / Map.of can hold at most 10 pairs — beyond that use Map.ofEntries(...).
- JShell lets you test Java interactively without files.
- JPMS modules group packages with clear exports and requirements.
- Interfaces can now have private helper methods.
- List.of / Set.of / Map.of create short, immutable collections.
- try-with-resources can use existing variables (Java 9).
- New stream helpers: Optional.stream(), Stream.ofNullable().