Mohammed Fazuluddin | Technical Architect
Java Version(v5 -v23) Features
Feature Short Description Example Code Snippet
Generics
Enables type safety in collections and eliminates type
casting.
List<String> list = new ArrayList<>(); list.add("Hello"); String s =
list.get(0);
Enhanced for Loop Simplifies iteration over collections or arrays. for (String s : list) { System.out.println(s); }
Autoboxing/Unboxing
Automatic conversion between primitives and wrapper
classes.
Integer num = 10; int n = num;
Enums Type-safe constants using enumeration types. enum Day { MONDAY, TUESDAY; } Day today = Day.MONDAY;
Varargs
Enables methods to accept variable numbers of
arguments.
void printArgs(String... args) { for (String s : args) {
System.out.println(s); } }
Feature Short Description Example Code Snippet
Scripting API Integration with scripting languages like JavaScript.
ScriptEngine engine = new
ScriptEngineManager().getEngineByName("JavaScript");
engine.eval("print('Hello World');");
Pluggable Annotation API Allows processing custom annotations at compile-time. @interface CustomAnnotation { String value(); }
Version-7
Feature Short Description Example Code Snippet
Try-with-resources
Simplifies resource management by auto-closing
resources.
try (BufferedReader br = new BufferedReader(new
FileReader("file.txt"))) { System.out.println(br.readLine()); }
Switch with Strings Adds support for string-based switch statements. switch (value) { case "A": System.out.println("A"); break; }
Diamond Operator Reduces boilerplate code when instantiating generics. List<String> list = new ArrayList<>();
NIO.2 Enhances file handling, including the Path API. Path path = Paths.get("file.txt"); Files.readAllLines(path);
Version-8
Feature Short Description Example Code Snippet
Lambda Expressions Adds functional-style programming to Java. list.forEach(item -> System.out.println(item));
Stream API Simplifies processing collections in a functional style. list.stream().filter(s -> s.startsWith("A")).forEach(System.out::println);
Default Methods Enables interface methods with default implementations.
interface MyInterface { default void show() {
System.out.println("Default method"); } }
Date-Time API Introduces a new and improved date-time library. LocalDate date = LocalDate.now();
Optional Avoids NullPointerException by wrapping nullable values.
Optional<String> opt = Optional.ofNullable(value);
opt.ifPresent(System.out::println);
Version-9
Feature Short Description Example Code Snippet
Module System Adds modularity for better code organization. module com.example { requires java.base; }
JShell Interactive REPL for Java code execution. jshell> System.out.println("Hello, World!");
Improved Stream API Adds methods like takeWhile, dropWhile, and iterate. Stream.of(1, 2, 3).takeWhile(x -> x < 3).forEach(System.out::println);
Version-10
Feature Short Description Example Code Snippet
Local Variable Type Inference Introduces var for inferred variable types. var list = new ArrayList<String>();
Version-11
Feature Short Description Example Code Snippet
HTTP Client API Simplifies making HTTP requests.
HttpClient client = HttpClient.newHttpClient(); HttpResponse<String>
response = client.send(request, BodyHandlers.ofString());
String Methods Adds useful string operations like isBlank, lines, and strip. "Hello ".strip();
Running Single File Programs
Simplifies running small Java programs without
compilation.
java HelloWorld.java
Version-12
Feature Short Description Example Code Snippet
Switch Expressions (Preview)
Simplifies switch statements by making them
expressions.
String result = switch (day) { case MONDAY -> "Start"; default ->
"End"; };
Compact Number Formatting Formats numbers compactly.
NumberFormat nf =
NumberFormat.getCompactNumberInstance(Locale.US,
Style.SHORT); nf.format(1000);
Version-13
Feature Short Description Example Code Snippet
Text Blocks (Preview) Simplifies multiline string literals. String json = """ { "key": "value" } """;
Version-14
Feature Short Description Example Code Snippet
Record Classes (Preview) Introduces concise classes for immutable data. record Point(int x, int y) { }
Helpful NullPointerExceptions
Provides detailed error messages for null pointer
exceptions.
obj.method(); with NullPointerException showing context.
Version-15
Feature Short Description Example Code Snippet
Sealed Classes (Preview)
Restricts which classes can extend or implement a
class/interface.
sealed class Shape permits Circle, Rectangle { }
Version-16
Feature Short Description Example Code Snippet
Records (Finalized) Simplified immutable data carriers finalized from preview. record Point(int x, int y) { }
Pattern Matching (Preview) Simplifies type checks in instanceof. if (obj instanceof String s) { System.out.println(s); }
Version-17
Feature Short Description Example Code Snippet
Sealed Classes (Finalized) Finalizes sealed classes. sealed class Shape permits Circle, Rectangle { }
Pattern Matching for Switch Adds pattern matching in switch statements. switch (obj) { case String s -> System.out.println(s); }
Version-19
Feature Short Description Example Code Snippet
Virtual Threads (Preview) Lightweight threads for better concurrency. Thread.startVirtualThread(() -> System.out.println("Hello"));
Structured Concurrency
Simplifies multithreaded programming with a structured
approach.
try (var scope = new StructuredTaskScope.ShutdownOnFailure()) { }
Version-20
Feature Short Description Example Code Snippet
Scoped Values (Preview) Provides a way to safely share data between threads. ScopedValue.newValue();
Version-21
Feature Short Description Example Code Snippet
Generational ZGC
Improves performance of the low-latency garbage
collector.
Internally optimized, no user code changes.
String Templates Allows embedding expressions in strings. String result = STR."Value: #{value}";
Version-23
Feature Short Description Example Code Snippet
Future Features (Speculated)
Continued enhancements in performance, native support,
and new programming paradigms.
To be announced.
Java Version(v5 -v23) Features with sample code snippet

Java Version(v5 -v23) Features with sample code snippet

  • 1.
    Mohammed Fazuluddin |Technical Architect Java Version(v5 -v23) Features
  • 2.
    Feature Short DescriptionExample Code Snippet Generics Enables type safety in collections and eliminates type casting. List<String> list = new ArrayList<>(); list.add("Hello"); String s = list.get(0); Enhanced for Loop Simplifies iteration over collections or arrays. for (String s : list) { System.out.println(s); } Autoboxing/Unboxing Automatic conversion between primitives and wrapper classes. Integer num = 10; int n = num; Enums Type-safe constants using enumeration types. enum Day { MONDAY, TUESDAY; } Day today = Day.MONDAY; Varargs Enables methods to accept variable numbers of arguments. void printArgs(String... args) { for (String s : args) { System.out.println(s); } }
  • 3.
    Feature Short DescriptionExample Code Snippet Scripting API Integration with scripting languages like JavaScript. ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript"); engine.eval("print('Hello World');"); Pluggable Annotation API Allows processing custom annotations at compile-time. @interface CustomAnnotation { String value(); }
  • 4.
    Version-7 Feature Short DescriptionExample Code Snippet Try-with-resources Simplifies resource management by auto-closing resources. try (BufferedReader br = new BufferedReader(new FileReader("file.txt"))) { System.out.println(br.readLine()); } Switch with Strings Adds support for string-based switch statements. switch (value) { case "A": System.out.println("A"); break; } Diamond Operator Reduces boilerplate code when instantiating generics. List<String> list = new ArrayList<>(); NIO.2 Enhances file handling, including the Path API. Path path = Paths.get("file.txt"); Files.readAllLines(path);
  • 5.
    Version-8 Feature Short DescriptionExample Code Snippet Lambda Expressions Adds functional-style programming to Java. list.forEach(item -> System.out.println(item)); Stream API Simplifies processing collections in a functional style. list.stream().filter(s -> s.startsWith("A")).forEach(System.out::println); Default Methods Enables interface methods with default implementations. interface MyInterface { default void show() { System.out.println("Default method"); } } Date-Time API Introduces a new and improved date-time library. LocalDate date = LocalDate.now(); Optional Avoids NullPointerException by wrapping nullable values. Optional<String> opt = Optional.ofNullable(value); opt.ifPresent(System.out::println);
  • 6.
    Version-9 Feature Short DescriptionExample Code Snippet Module System Adds modularity for better code organization. module com.example { requires java.base; } JShell Interactive REPL for Java code execution. jshell> System.out.println("Hello, World!"); Improved Stream API Adds methods like takeWhile, dropWhile, and iterate. Stream.of(1, 2, 3).takeWhile(x -> x < 3).forEach(System.out::println);
  • 7.
    Version-10 Feature Short DescriptionExample Code Snippet Local Variable Type Inference Introduces var for inferred variable types. var list = new ArrayList<String>();
  • 8.
    Version-11 Feature Short DescriptionExample Code Snippet HTTP Client API Simplifies making HTTP requests. HttpClient client = HttpClient.newHttpClient(); HttpResponse<String> response = client.send(request, BodyHandlers.ofString()); String Methods Adds useful string operations like isBlank, lines, and strip. "Hello ".strip(); Running Single File Programs Simplifies running small Java programs without compilation. java HelloWorld.java
  • 9.
    Version-12 Feature Short DescriptionExample Code Snippet Switch Expressions (Preview) Simplifies switch statements by making them expressions. String result = switch (day) { case MONDAY -> "Start"; default -> "End"; }; Compact Number Formatting Formats numbers compactly. NumberFormat nf = NumberFormat.getCompactNumberInstance(Locale.US, Style.SHORT); nf.format(1000);
  • 10.
    Version-13 Feature Short DescriptionExample Code Snippet Text Blocks (Preview) Simplifies multiline string literals. String json = """ { "key": "value" } """;
  • 11.
    Version-14 Feature Short DescriptionExample Code Snippet Record Classes (Preview) Introduces concise classes for immutable data. record Point(int x, int y) { } Helpful NullPointerExceptions Provides detailed error messages for null pointer exceptions. obj.method(); with NullPointerException showing context.
  • 12.
    Version-15 Feature Short DescriptionExample Code Snippet Sealed Classes (Preview) Restricts which classes can extend or implement a class/interface. sealed class Shape permits Circle, Rectangle { }
  • 13.
    Version-16 Feature Short DescriptionExample Code Snippet Records (Finalized) Simplified immutable data carriers finalized from preview. record Point(int x, int y) { } Pattern Matching (Preview) Simplifies type checks in instanceof. if (obj instanceof String s) { System.out.println(s); }
  • 14.
    Version-17 Feature Short DescriptionExample Code Snippet Sealed Classes (Finalized) Finalizes sealed classes. sealed class Shape permits Circle, Rectangle { } Pattern Matching for Switch Adds pattern matching in switch statements. switch (obj) { case String s -> System.out.println(s); }
  • 15.
    Version-19 Feature Short DescriptionExample Code Snippet Virtual Threads (Preview) Lightweight threads for better concurrency. Thread.startVirtualThread(() -> System.out.println("Hello")); Structured Concurrency Simplifies multithreaded programming with a structured approach. try (var scope = new StructuredTaskScope.ShutdownOnFailure()) { }
  • 16.
    Version-20 Feature Short DescriptionExample Code Snippet Scoped Values (Preview) Provides a way to safely share data between threads. ScopedValue.newValue();
  • 17.
    Version-21 Feature Short DescriptionExample Code Snippet Generational ZGC Improves performance of the low-latency garbage collector. Internally optimized, no user code changes. String Templates Allows embedding expressions in strings. String result = STR."Value: #{value}";
  • 18.
    Version-23 Feature Short DescriptionExample Code Snippet Future Features (Speculated) Continued enhancements in performance, native support, and new programming paradigms. To be announced.