0% found this document useful (0 votes)
46 views2 pages

Java 8 To 12 Features Explained

The document outlines key features introduced in Java versions 8 to 12, highlighting their purpose, usage, and real-time examples. Java 8 introduced lambda expressions for functional programming, Java 9 added JShell for interactive code execution, Java 10 introduced the var keyword for simplified variable declarations, Java 11 added new string methods for easier operations, and Java 12 introduced switch expressions to enhance clarity in switch-case blocks. Each feature aims to reduce verbosity and improve the efficiency of coding in Java.

Uploaded by

Ranganath G
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views2 pages

Java 8 To 12 Features Explained

The document outlines key features introduced in Java versions 8 to 12, highlighting their purpose, usage, and real-time examples. Java 8 introduced lambda expressions for functional programming, Java 9 added JShell for interactive code execution, Java 10 introduced the var keyword for simplified variable declarations, Java 11 added new string methods for easier operations, and Java 12 introduced switch expressions to enhance clarity in switch-case blocks. Each feature aims to reduce verbosity and improve the efficiency of coding in Java.

Uploaded by

Ranganath G
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Java 8 to Java 21 Features - Explained

Clearly
Java 8 - Lambda Expressions
 👉 WHY INTRODUCED:
To reduce boilerplate and introduce functional programming into Java. Anonymous
classes were too verbose.
 📌 WHERE USED:
Used in event handling, filtering data, multi-threading (Runnable), sorting.
 💡 REAL-TIME EXAMPLE:

List<String> names = [Link]("Raj", "Ravi", "Ram");


[Link]((s1, s2) -> [Link](s2));

Java 9 - JShell
 👉 WHY INTRODUCED:
To allow interactive execution of Java code for learning and testing quickly.
 📌 WHERE USED:
Used in learning environments, testing logic without writing full classes.
 💡 REAL-TIME EXAMPLE:

jshell> int a = 5;
jshell> int b = 10;
jshell> a + b
Output: 15

Java 10 - var Keyword


 👉 WHY INTRODUCED:
To simplify local variable declarations when the type is clear, reducing verbosity.
 📌 WHERE USED:
Used in local variables, loop variables, try-with-resources.
 💡 REAL-TIME EXAMPLE:

var name = "Ranganath"; // Inferred as String


var list = new ArrayList<String>(); // Inferred as ArrayList<String>
Java 11 - New String Methods
 👉 WHY INTRODUCED:
To make common string operations easier like blank check, line splitting, and repetition.
 📌 WHERE USED:
Used in input validation, text parsing, formatting.
 💡 REAL-TIME EXAMPLE:

[Link](" ".isBlank()); // true


"Hello\nWorld".lines().forEach([Link]::println);
[Link]("Ha".repeat(3)); // HaHaHa

Java 12 - Switch Expressions (Preview)


 👉 WHY INTRODUCED:
To reduce the verbosity and increase clarity in switch-case blocks.
 📌 WHERE USED:
Used in decision making where switch returns a value.
 💡 REAL-TIME EXAMPLE:

int day = 2;
String result = switch (day) {
case 1 -> "Monday";
case 2 -> "Tuesday";
default -> "Other";
};
[Link](result);

You might also like