Java Features Flashcards
Java 8 (2014)
Feature Description
Lambda Expressions Enables functional programming using (params) -> expression.
Functional Interfaces Interfaces with one abstract method (e.g., Function, Predicate).
Stream API Functional operations on collections like filter(), map(), reduce().
Default & Static Methods Interface methods with implementation using default and static.
Optional Class Avoids null checks with Optional.of(), Optional.empty().
New Date & Time API Immutable classes like LocalDate, LocalDateTime.
Nashorn Engine Run JavaScript within Java code.
Method References Shorter syntax for lambdas using ClassName::methodName.
Java 17 (2021 - LTS)
Feature Description
Sealed Classes Restrict which classes can extend a class.
Pattern Matching (instanceof) Eliminates need for explicit casting.
Records Concise immutable data carriers with record keyword.
Text Blocks Multiline string literals using triple quotes """.
Switch Expressions Use switch as an expression with arrow syntax.
New Random Generators Enhanced API for pseudo-random number generation.
Java 21 (2023 - LTS)
Feature Description
Virtual Threads Lightweight threads from Project Loom.
Pattern Matching for Switch Use switch with pattern types.
Record Patterns Deconstruct records directly inside conditions.
Sequenced Collections Preserve insertion order (SequencedSet, SequencedMap).
Scoped Values Safe data sharing across threads, alternative to ThreadLocal.
String Templates (Preview) Inline expressions in strings: STR."Hello, {name}".
Unnamed Variables (Preview) Use _ for unused pattern components.