0% found this document useful (0 votes)
5 views4 pages

Java_Concepts_Notes

The document discusses advanced Java concepts including functional interfaces, default and static methods, lambda expressions, method references, and the Stream API introduced in Java 8. It also covers Base64 encoding, the try-with-resources feature from Java 7, annotations, type annotations, repeating annotations, and the Java Module System introduced in Java 9. Each concept is accompanied by examples to illustrate their usage.

Uploaded by

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

Java_Concepts_Notes

The document discusses advanced Java concepts including functional interfaces, default and static methods, lambda expressions, method references, and the Stream API introduced in Java 8. It also covers Base64 encoding, the try-with-resources feature from Java 7, annotations, type annotations, repeating annotations, and the Java Module System introduced in Java 9. Each concept is accompanied by examples to illustrate their usage.

Uploaded by

vivekladduu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Java Advanced Concepts (Functional Interface to Module System)

1. Functional Interface

Functional Interface ek aisa interface hota hai jisme sirf ek abstract method hota hai. Java 8 se introduced

hua tha, jiska use lambda expressions ke sath hota hai.

Example:

@FunctionalInterface

interface MyFunc {

void sayHello();

2. Default and Static Methods in Interface

Java 8 mein interface mein default aur static methods define karne ki facility di gayi hai.

- default method: Instance method with default keyword.

- static method: Directly call via interface name.

Example:

interface MyInterface {

default void show() { System.out.println("Default Method"); }

static void display() { System.out.println("Static Method"); }

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)

(parameter) -> { body }

Example:

MyFunc m = () -> System.out.println("Hello");

4. Method Reference

Method reference ek short-hand lambda expression hai jisme directly existing method ko refer kiya jata hai.

Syntax: ClassName::methodName

Example:

List<String> names = Arrays.asList("A", "B");

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:

List<String> list = Arrays.asList("a", "b");

list.stream().filter(s -> s.equals("a")).forEach(System.out::println);

6. Base64 Encoding and Decoding

Base64 Encoding binary data ko text mein convert karta hai.

Example:

String encoded = Base64.getEncoder().encodeToString("Hello".getBytes());


Java Advanced Concepts (Functional Interface to Module System)

byte[] decoded = Base64.getDecoder().decode(encoded);

7. forEach() Method with Stream

forEach() ek terminal operation hai jo har stream element par operation perform karta hai.

Example:

list.stream().forEach(e -> System.out.println(e));

8. try-with-resources

Java 7 se try-with-resources feature introduce hua jisme AutoCloseable resources ko automatically close kiya

jata hai.

Example:

try (BufferedReader br = new BufferedReader(new FileReader("file.txt"))) {

br.readLine();

9. Annotations

Annotations metadata provide karte hain. Common annotations: @Override, @Deprecated,

@SuppressWarnings

Example:

@Override

public void run() {}

10. Type Annotations


Java Advanced Concepts (Functional Interface to Module System)

Java 8 se introduce hua. Use: @Target(ElementType.TYPE_USE)

Example:

@NonNull String name;

List<@NonNull String> names;

11. Repeating Annotations

Java 8 se ek annotation ko multiple times apply kar sakte hain.

Example:

@Role("admin")

@Role("user")

public class User {}

12. Java Module System

Java 9 se introduce hua. Modules application ko divide karte hain.

Example:

module my.module {

requires another.module;

exports com.example;

You might also like