Skip to content

PRO TIP Block youtube.com at the DNS level — Pi-hole, NextDNS or your hosts file — but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

#74 Lambda Expression in Java

266.7K views on YouTube

Check out our courses:

Mastering Agentic AI with Java : https://go.telusko.com/agentic-ai
Coupon: TELUSKO10 (10% Discount)

DevOps Bootcamp: https://go.telusko.com/complete-devops
Coupon: TELUSKO10 (10% Discount)

Master Java Spring Development : https://go.telusko.com/learn-master
Coupon: TELUSKO10 (10% Discount)

For More Queries WhatsApp or Call on : +919008963671

website : https://telusko.com/

Udemy Courses:

Java Spring:- https://go.telusko.com/Udemyjavaspring
Java:- https://go.telusko.com/udemyteluskojava
Spring: https://go.telusko.com/udemyteluskospring
Java For Programmers:- https://go.telusko.com/javaProgrammers
Python : https://go.telusko.com/udemyteluskopython
Git : https://go.telusko.com/udemyteluskogit
Docker : https://go.telusko.com/udemyteluskodocker

Instagram : https://www.instagram.com/navinreddyofficial/
Linkedin : https://in.linkedin.com/in/navinreddy20
WhatsApp : https://go.telusko.com/whatsapp
TELUSKO Android App : https://go.telusko.com/TELUSKOAPP
TELUSKO IOS App : https://apple.co/3SsgmU2
Discord : https://discord.gg/D8hWe9BqfF

In this lecture, we are discussing lambda expression:
#1 what is lambda expression in java?
— In Java, a lambda expression is a concise way to implement a functional interface.
A functional interface is an interface that has only one abstract method, and it can be implemented using a lambda expression.
— In the previous lecture we see that we are making a class or inner class to implement the functional interface
but using lambda expression we do not need of new class and inner class to implement.

#2 Properties of the lambda expression
Concise syntax: Lambda expressions provide a concise and expressive syntax for defining functional interfaces.
They allow you to define the behaviour of a functional interface in a single line of code.

Functional programming: Lambda expressions are a key component of functional programming in Java.
They allow you to write code that is more declarative and expressive, and less verbose than traditional imperative code.

No need for anonymous inner classes: Lambda expressions provide an alternative to anonymous inner classes, which are often
used to implement functional interfaces in Java. Lambda expressions are more concise and easier to read than anonymous inner classes.

#3 example:

class Main{
public static void main(String []args){
A obj = new B();
obj.show();

//another way to implement functional interface
A obj1 = new A(){
@Override
public void show(){
System.out.println(“Hello”);
}
};
obj1.show();

//now we can use a lambda expression to implement the functional interface
//you can remove new A() and public void show() and replace it with () -grater then System.out.println(“Hello”);
//if you have single statements you need not mention curly braces and return keyword

A obj2 = () – grater then System.out.println(“Hello”);
obj2.show();

//here you can use lambda expression to implement interface C
C obj3= i-grater then System.out.println(i);
obj3.show(5);

}
}
//one way to implement functional interface
class B implements A{
@Override
public void show(){
System.out.println(“Hello”);
}
}

//specify it is functional interface
@FunctionalInterface //we use this annotation to specify it is functional interface
interface A{
void show();
//void run(); //this will give error as it is not functional interface
}

interface C{
public void show(int i);
}

Github repo : https://github.com/navinreddy20/Javacode.git

More Learning :

Java :- https://bit.ly/3x6rr0N
Python :- https://bit.ly/3GRc7JX
Django :- https://bit.ly/3MmoJK6

JavaScript :- https://bit.ly/3tiAlHo
Node JS :- https://bit.ly/3GT4liq

Rest Api :-https://bit.ly/3MjhZwt
Servlet :- https://bit.ly/3Q7eA7k
Spring Framework :- https://bit.ly/3xi7buh
Design Patterns in Java :- https://bit.ly/3MocXiq
Docker :- https://bit.ly/3xjWzLA

Blockchain Tutorial :- https://bit.ly/3NSbOkc
Corda Tutorial:- https://bit.ly/3thbUKa
Hyperledger Fabric :- https://bit.ly/38RZCRB

NoSQL Tutorial :- https://bit.ly/3aJpRuc
Mysql Tutorial :- https://bit.ly/3thpr4L

Data Structures using Java :- https://bit.ly/3MuJa7S
Git Tutorial :- https://bit.ly/3NXyCPu

Donation:
PayPal Id : navinreddy20
https://www.telusko.com