Java Lambda — தமிழ்

</>Coding Tamilan.← Java course & curriculum
Java Masterclass · Lesson 49 / 50 · தமிழ்

Java Lambda

Pass a small behavior as a value.

Step-by-step explanationsRunnable JavaPractice + answer

முக்கிய விளக்கங்கள் தமிழில் உள்ளன. Runnable example மற்றும் கூடுதல் practice notes ஆங்கிலத்தில் உள்ளன.

இந்தப் பாடத்தில்…

  • Explain the key idea behind Lambda Expressions.
  • Read and run a complete example, then predict what changes.
  • Recognize the topic-specific mistake discussed below.
01 / The concept

அடிப்படையைப் புரிந்துகொள்ளுங்கள்

A lambda supplies an implementation for a functional interface: an interface with one abstract method. It is useful for short callbacks and transformations. A captured local variable must be final or effectively final; keep side effects deliberate.

02 / Step by step

விரிவான விளக்கங்கள்

Java Lambda Expressions என்னன்னு தெரியுமா?

Lambda expression என்பது anonymous function-ஐ concise-ஆ எழுதுங்கள்வது. Java 8-ல introduce ஆச்சு.

Lambda syntax:

Java reference fragmentJAVA
parameter -> expression
(parameter1, parameter2) -> expression
(parameter1, parameter2) -> { code block }

Lambda with ArrayList

ArrayList-ஐ forEach-ல iterate பண்றதுக்கு lambda use பண்ணலாம்:

Lambda expressions code-ஐ shorter-ஆ, readable-ஆ வையுங்கள்க்கும். Functional interfaces-உடன் use பண்றோம்.

Lambdas with Stream API

Java reference fragmentJAVA
List<String> names = List.of("Alice", "Bob", "Charlie", "Anna");

// filter + map + collect
List<String> result = names.stream()
    .filter(n -> n.startsWith("A"))
    .map(String::toUpperCase)
    .collect(Collectors.toList());
// [ALICE, ANNA]

// reduce
int total = List.of(1,2,3,4,5).stream()
    .reduce(0, Integer::sum);  // 15

Method References

Reference typeSyntaxExample
Static methodClassName::methodMath::sqrt
Instance method (on object)instance::methodstr::toUpperCase
Instance method (on type)ClassName::methodString::toUpperCase
ConstructorClassName::newArrayList::new

Lambda + Streams = Modern Java: Java 8-ல் வந்த Lambdas மற்றும் Streams API, modern Java development-ன் backbone. list.stream().filter().map().collect() pattern — for loops-ஐ விட readable, declarative, மற்றும் parallel execution-க்கு ready. Interview-ல் இதை fluently பேசுவது Senior Developer level-ஐ demonstrate செய்யும்.

03 / Read and predict

முழுமையான உதாரணம்

This complete Main.java program focuses on the lesson idea. Reference fragments above may demonstrate individual statements; this example includes the imports, entry point, and supporting types it needs.

Main.java · complete runnable exampleJAVA
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        List<Integer> values = Arrays.asList(1, 2, 3);
        values.forEach(n -> System.out.println(n * 2));
    }
}
Predict first. Then reveal the expected output / வெளியீடு
2
4
6

The output shown was checked by running this complete example. Trace the executed statements in order, then compare with your run.

04 / Learn by changing

Change it. Run it. Understand it.

Load this lesson example into the editor. Change one value or statement, predict the result, then press RUN to execute Java.

Open Java editor ↗
After the editor loads, choose Load this lesson example, then press RUN.

Powered by OneCompiler. Code you run is sent to OneCompiler for execution. For Scanner examples, supply input in the editor I/O panel; for file examples, files exist in its execution environment.

05 / Your turn

நீங்களே முயற்சி செய்யுங்கள்

Practice challenge

Change the expression so it prints the square of each value.

Reveal the answer and reasoning / விடை

Use n * n to produce 1, 4, and 9.

தவிர்க்க வேண்டிய தவறு: A lambda is not automatically asynchronous or parallel. The calling API determines when and how it executes.

பாடத்தின் சுருக்கம்

  • Explain the example without reading the output first.
  • Make the change requested in the practice task.
  • Describe why the result changed—or why compilation failed.

Ready to move on? Follow the next lesson in course order, or return to the curriculum to review a prerequisite.

Coding Tamilan · Understand the idea. Try the code. Build the habit.