Java_Concepts_Notes
Java_Concepts_Notes
1. Functional Interface
Functional Interface ek aisa interface hota hai jisme sirf ek abstract method hota hai. Java 8 se introduced
Example:
@FunctionalInterface
interface MyFunc {
void sayHello();
Java 8 mein interface mein default aur static methods define karne ki facility di gayi hai.
Example:
interface MyInterface {
3. Lambda Expression
Lambda expression ek short form hota hai anonymous function ka. Functional Interface ke sath use hota hai.
Syntax:
Java Advanced Concepts (Functional Interface to Module System)
Example:
4. Method Reference
Method reference ek short-hand lambda expression hai jisme directly existing method ko refer kiya jata hai.
Syntax: ClassName::methodName
Example:
names.forEach(System.out::println);
5. Stream API
Stream API Java 8 se introduce hua tha jiska use data processing (filter, map, collect, etc.) ke liye hota hai.
Example:
Example:
forEach() ek terminal operation hai jo har stream element par operation perform karta hai.
Example:
8. try-with-resources
Java 7 se try-with-resources feature introduce hua jisme AutoCloseable resources ko automatically close kiya
jata hai.
Example:
br.readLine();
9. Annotations
@SuppressWarnings
Example:
@Override
Example:
Example:
@Role("admin")
@Role("user")
Example:
module my.module {
requires another.module;
exports com.example;