SlideShare a Scribd company logo
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Training | Edureka
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
01
02
03
05
06
07
Java Lambda Expressions
Functional Interface
Lambda Parameters
Lambda as an Object
Lambda Value Capture
Method References as
Lambdas
Topics For Today’s Discussion
Java Lambda
Expressions
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
It provides the implementation of a functional interface & simplifies the software development
It provides a clear and concise way to represent a method interface via an expression
Java Lambda Expressions
It is an anonymous function that doesn’t have a name and doesn’t belong to any class
Java lambda expressions are Java's first step into functional programming
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
parameter -> expression body->
Java Lambda Expressions
Syntax
Characteristics
-> Optional Type Declarations
-> Optional Parenthesis Around Parameters
-> Optional Curly Braces
-> Optional return keyword
Arrow Operator is introduced in Java through lambda
expressions that divides it into two parts i.e Parameters & Body
Functional
Interface
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Functional Interface
Functional Interface is
an interface that
contains exactly one
abstract method
It can have any
number of default or
static methods along
with object class
methods
Java provides
predefined functional
interfaces to deal with
functional
programming
Runnable,
ActionListener,
Comparable are some
of the examples of
functional interfaces
01 02 03 04
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Functional Interface
@FunctionalInterface
interface displayable{
void display(String msg);
}
public class Test implements displayable{
public void display(String msg){
System.out.println(msg);
}
public static void main(String[] args) {
Test dis = new Test();
dis.display("Welcome to Lambda Tutorial by Edureka!");
}
}
Lambda
parameters
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Lambda Parameters
Lambda Expressions can take parameters just like methods
1 2 3
Zero Parameters One Parameter Multiple Parameters
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Lambda Parameters
1
2
3
Zero Parameters
One Parameter
Multiple Parameters
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Lambda Parameters
1
2
3
Zero Parameters
One Parameter
Multiple Parameters
() -> System.out.println("Zero parameter lambda");
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Lambda Parameters
1
2
3
Zero Parameters
One Parameter
Multiple Parameters
() -> System.out.println("Zero parameter lambda");
(param) -> System.out.println("One parameter: " + param);
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Lambda Parameters
1
2
3
Zero Parameters
One Parameter
Multiple Parameters
() -> System.out.println("Zero parameter lambda");
(param) -> System.out.println("One parameter: " + param);
(p1, p2) -> System.out.println("Multiple parameters: " +
p1 + ", " + p2);
Lambda As An
object
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Lambda as an Object
A Java lambda expression is essentially an object that can be assigned to a variable and passed around
public interface LambdaComparator {
public boolean compare(int a1, int a2);
}
LambdaComparator myComparator = (a1, a2) -> return a1 > a2;
boolean result = myComparator.compare(2, 5);
Interface
Implementing
class
Lambda Variable
Capture
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Variable Capture
Java lambda expression can access variables that are declared outside the lambda function body under
certain circumstances
1 2 3
Local Variable Instance Variables Static Variables
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Lambda Parameters
1
2
3
Local Variable
Instance Variables
Static Variables
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Lambda Parameters
1
2
3
Local Variable
String myStr = "Welcome to Edureka!";
MyLambda dis = (chars) -> {
return myStr + ":" + new String(chars);
};
Instance Variables
Static Variables
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Lambda Parameters
1
2
3
Local Variable
Instance Variables
Static Variables
public class LambdaStaticConsumerDemo {
private String str = "Lambda Consumer";
public void attach(LambdaStaticProducerDemo eventProd){
eventProd.listen(e -> {
System.out.println(this.str);
});
}
}
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Lambda Parameters
1
2
3
Local Variable
Instance Variables
Static Variables
public class LambdaStaticConsumerDemo {
private static String myStaticVar = "Edureka!";
public void attach(LambdaStaticProducerDemo eventProd){
eventProd.listen(e -> {
System.out.println(myStaticVar);
});
}
}
Method references
As lambdas
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Method References
Java lambda expression can access variables that are declared outside the lambda function body under
certain circumstances
Static Method
Reference
1 2 3 4
Parameter Method
Reference
Instance Method
Reference
Constructor Method
Reference
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Method References
Static Method
Reference
1
2
3
4
Parameter Method
Reference
Instance Method
Reference
Constructor Method
Reference
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Class
Lambda Expression
Interface
Method References - Static
Static Method
Reference1
2
3
4
Parameter Method
Reference
Instance Method
Reference
Constructor Method
Reference
public interface Display {
public int show(String s1, String s2);
}
public class Test{
public static int doShow(String s1, String s2){
return s1.lastIndexOf(s2);
}
}
Display disp = Test::doShow;
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Method References - Parameter
Static Method
Reference
1
2
3
4
Parameter Method
Reference
Instance Method
Reference
Constructor Method
Reference
Interface
public interface Display {
public int show(String s1, String s2);
}
Lambda Expression
Display disp = String::indexOf;
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Method References - Instance
Static Method
Reference
1
2
3
4
Parameter Method
Reference
Instance Method
Reference
Constructor Method
Reference
Interface
public interface Deserializer {
public int deserialize(String v1);
}
Class
Lambda Expression
public class StringConverter {
public int convertToInt(String v1){
return Integer.valueOf(v1);
}
}
StringConverter strConv = new StringConverter();
Deserializer deserializer = strConv::convertToInt;
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Method References - Constructor
Static Method
Reference
1
2
3
4
Parameter Method
Reference
Instance Method
Reference
Constructor Method
Reference
Interface
public interface Factory {
public String create(char[] val);
}
Lambda Expression
Factory fact = String::new;
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Training | Edureka

More Related Content

What's hot (20)

Spring boot
Spring bootSpring boot
Spring boot
sdeeg
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
Naphachara Rattanawilai
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
Santosh Kumar Kar
 
Java8 features
Java8 featuresJava8 features
Java8 features
Elias Hasnat
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Trey Howard
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
Rohit Verma
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
Dzmitry Naskou
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
Venkata Naga Ravi
 
Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
Mike Ensor
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
Van Huong
 
Spring Boot
Spring BootSpring Boot
Spring Boot
Pei-Tang Huang
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
Alex Movila
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
NexThoughts Technologies
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
Sujit Majety
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Purbarun Chakrabarti
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Steve Pember
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
jaimefrozr
 
Strings in Java
Strings in Java Strings in Java
Strings in Java
Hitesh-Java
 
Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
Knoldus Inc.
 
Spring boot
Spring bootSpring boot
Spring boot
sdeeg
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Trey Howard
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
Rohit Verma
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
Dzmitry Naskou
 
Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
Mike Ensor
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
Van Huong
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
Alex Movila
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
Sujit Majety
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Steve Pember
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
jaimefrozr
 
Strings in Java
Strings in Java Strings in Java
Strings in Java
Hitesh-Java
 

Similar to Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Training | Edureka (20)

Unit-3.pptx.pdf java api knowledge apiii
Unit-3.pptx.pdf java api knowledge apiiiUnit-3.pptx.pdf java api knowledge apiii
Unit-3.pptx.pdf java api knowledge apiii
mpfbaa
 
Simple Lambdas in java in oca 8.0 on feb
Simple Lambdas in java in oca 8.0 on febSimple Lambdas in java in oca 8.0 on feb
Simple Lambdas in java in oca 8.0 on feb
krishmf1
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
langer4711
 
Java 8
Java 8Java 8
Java 8
Sheeban Singaram
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
Tobias Coetzee
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
NexThoughts Technologies
 
JDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
JDK8 Lambdas and Streams: Changing The Way You Think When Developing JavaJDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
JDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
Simon Ritter
 
Jf12 lambdas injava8-1
Jf12 lambdas injava8-1Jf12 lambdas injava8-1
Jf12 lambdas injava8-1
langer4711
 
Lambda Expression For anyone that needs Java Lambda notes
Lambda Expression For anyone that needs Java Lambda notesLambda Expression For anyone that needs Java Lambda notes
Lambda Expression For anyone that needs Java Lambda notes
shreyansh15388
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
Sanjoy Kumar Roy
 
Java Advanced Topic - Java Lambda Expressions.pptx
Java Advanced Topic - Java Lambda Expressions.pptxJava Advanced Topic - Java Lambda Expressions.pptx
Java Advanced Topic - Java Lambda Expressions.pptx
MuraliD32
 
Java8
Java8Java8
Java8
Felipe Mamud
 
Java 8 new features
Java 8 new featuresJava 8 new features
Java 8 new features
Aniket Thakur
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8
Bansilal Haudakari
 
Lambdas : Beyond The Basics
Lambdas : Beyond The BasicsLambdas : Beyond The Basics
Lambdas : Beyond The Basics
Simon Ritter
 
Lambdas, Collections Framework, Stream API
Lambdas, Collections Framework, Stream APILambdas, Collections Framework, Stream API
Lambdas, Collections Framework, Stream API
Prabu U
 
Week-1..................................
Week-1..................................Week-1..................................
Week-1..................................
kmjanani05
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
Maýur Chourasiya
 
Java SE 8
Java SE 8Java SE 8
Java SE 8
Murali Pachiyappan
 
LambdaExpressionInjavaforlearning fucntion
LambdaExpressionInjavaforlearning fucntionLambdaExpressionInjavaforlearning fucntion
LambdaExpressionInjavaforlearning fucntion
ShivamMishra465316
 
Unit-3.pptx.pdf java api knowledge apiii
Unit-3.pptx.pdf java api knowledge apiiiUnit-3.pptx.pdf java api knowledge apiii
Unit-3.pptx.pdf java api knowledge apiii
mpfbaa
 
Simple Lambdas in java in oca 8.0 on feb
Simple Lambdas in java in oca 8.0 on febSimple Lambdas in java in oca 8.0 on feb
Simple Lambdas in java in oca 8.0 on feb
krishmf1
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
langer4711
 
JDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
JDK8 Lambdas and Streams: Changing The Way You Think When Developing JavaJDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
JDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
Simon Ritter
 
Jf12 lambdas injava8-1
Jf12 lambdas injava8-1Jf12 lambdas injava8-1
Jf12 lambdas injava8-1
langer4711
 
Lambda Expression For anyone that needs Java Lambda notes
Lambda Expression For anyone that needs Java Lambda notesLambda Expression For anyone that needs Java Lambda notes
Lambda Expression For anyone that needs Java Lambda notes
shreyansh15388
 
Java Advanced Topic - Java Lambda Expressions.pptx
Java Advanced Topic - Java Lambda Expressions.pptxJava Advanced Topic - Java Lambda Expressions.pptx
Java Advanced Topic - Java Lambda Expressions.pptx
MuraliD32
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8
Bansilal Haudakari
 
Lambdas : Beyond The Basics
Lambdas : Beyond The BasicsLambdas : Beyond The Basics
Lambdas : Beyond The Basics
Simon Ritter
 
Lambdas, Collections Framework, Stream API
Lambdas, Collections Framework, Stream APILambdas, Collections Framework, Stream API
Lambdas, Collections Framework, Stream API
Prabu U
 
Week-1..................................
Week-1..................................Week-1..................................
Week-1..................................
kmjanani05
 
LambdaExpressionInjavaforlearning fucntion
LambdaExpressionInjavaforlearning fucntionLambdaExpressionInjavaforlearning fucntion
LambdaExpressionInjavaforlearning fucntion
ShivamMishra465316
 
Ad

More from Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
Edureka!
 
What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
Edureka!
 
Ad

Recently uploaded (20)

Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Soulmaite review - Find Real AI soulmate review
Soulmaite review - Find Real AI soulmate reviewSoulmaite review - Find Real AI soulmate review
Soulmaite review - Find Real AI soulmate review
Soulmaite
 
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | BluebashMCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
Bluebash
 
FCF- Getting Started in Cybersecurity 3.0
FCF- Getting Started in Cybersecurity 3.0FCF- Getting Started in Cybersecurity 3.0
FCF- Getting Started in Cybersecurity 3.0
RodrigoMori7
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to KnowWhat is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
SMACT Works
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Soulmaite review - Find Real AI soulmate review
Soulmaite review - Find Real AI soulmate reviewSoulmaite review - Find Real AI soulmate review
Soulmaite review - Find Real AI soulmate review
Soulmaite
 
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | BluebashMCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
Bluebash
 
FCF- Getting Started in Cybersecurity 3.0
FCF- Getting Started in Cybersecurity 3.0FCF- Getting Started in Cybersecurity 3.0
FCF- Getting Started in Cybersecurity 3.0
RodrigoMori7
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to KnowWhat is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
SMACT Works
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 

Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Training | Edureka

  • 2. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training 01 02 03 05 06 07 Java Lambda Expressions Functional Interface Lambda Parameters Lambda as an Object Lambda Value Capture Method References as Lambdas Topics For Today’s Discussion
  • 4. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training It provides the implementation of a functional interface & simplifies the software development It provides a clear and concise way to represent a method interface via an expression Java Lambda Expressions It is an anonymous function that doesn’t have a name and doesn’t belong to any class Java lambda expressions are Java's first step into functional programming
  • 5. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training parameter -> expression body-> Java Lambda Expressions Syntax Characteristics -> Optional Type Declarations -> Optional Parenthesis Around Parameters -> Optional Curly Braces -> Optional return keyword Arrow Operator is introduced in Java through lambda expressions that divides it into two parts i.e Parameters & Body
  • 7. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Functional Interface Functional Interface is an interface that contains exactly one abstract method It can have any number of default or static methods along with object class methods Java provides predefined functional interfaces to deal with functional programming Runnable, ActionListener, Comparable are some of the examples of functional interfaces 01 02 03 04
  • 8. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Functional Interface @FunctionalInterface interface displayable{ void display(String msg); } public class Test implements displayable{ public void display(String msg){ System.out.println(msg); } public static void main(String[] args) { Test dis = new Test(); dis.display("Welcome to Lambda Tutorial by Edureka!"); } }
  • 10. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Lambda Parameters Lambda Expressions can take parameters just like methods 1 2 3 Zero Parameters One Parameter Multiple Parameters
  • 11. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Lambda Parameters 1 2 3 Zero Parameters One Parameter Multiple Parameters
  • 12. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Lambda Parameters 1 2 3 Zero Parameters One Parameter Multiple Parameters () -> System.out.println("Zero parameter lambda");
  • 13. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Lambda Parameters 1 2 3 Zero Parameters One Parameter Multiple Parameters () -> System.out.println("Zero parameter lambda"); (param) -> System.out.println("One parameter: " + param);
  • 14. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Lambda Parameters 1 2 3 Zero Parameters One Parameter Multiple Parameters () -> System.out.println("Zero parameter lambda"); (param) -> System.out.println("One parameter: " + param); (p1, p2) -> System.out.println("Multiple parameters: " + p1 + ", " + p2);
  • 16. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Lambda as an Object A Java lambda expression is essentially an object that can be assigned to a variable and passed around public interface LambdaComparator { public boolean compare(int a1, int a2); } LambdaComparator myComparator = (a1, a2) -> return a1 > a2; boolean result = myComparator.compare(2, 5); Interface Implementing class
  • 18. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Variable Capture Java lambda expression can access variables that are declared outside the lambda function body under certain circumstances 1 2 3 Local Variable Instance Variables Static Variables
  • 19. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Lambda Parameters 1 2 3 Local Variable Instance Variables Static Variables
  • 20. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Lambda Parameters 1 2 3 Local Variable String myStr = "Welcome to Edureka!"; MyLambda dis = (chars) -> { return myStr + ":" + new String(chars); }; Instance Variables Static Variables
  • 21. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Lambda Parameters 1 2 3 Local Variable Instance Variables Static Variables public class LambdaStaticConsumerDemo { private String str = "Lambda Consumer"; public void attach(LambdaStaticProducerDemo eventProd){ eventProd.listen(e -> { System.out.println(this.str); }); } }
  • 22. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Lambda Parameters 1 2 3 Local Variable Instance Variables Static Variables public class LambdaStaticConsumerDemo { private static String myStaticVar = "Edureka!"; public void attach(LambdaStaticProducerDemo eventProd){ eventProd.listen(e -> { System.out.println(myStaticVar); }); } }
  • 24. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Method References Java lambda expression can access variables that are declared outside the lambda function body under certain circumstances Static Method Reference 1 2 3 4 Parameter Method Reference Instance Method Reference Constructor Method Reference
  • 25. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Method References Static Method Reference 1 2 3 4 Parameter Method Reference Instance Method Reference Constructor Method Reference
  • 26. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Class Lambda Expression Interface Method References - Static Static Method Reference1 2 3 4 Parameter Method Reference Instance Method Reference Constructor Method Reference public interface Display { public int show(String s1, String s2); } public class Test{ public static int doShow(String s1, String s2){ return s1.lastIndexOf(s2); } } Display disp = Test::doShow;
  • 27. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Method References - Parameter Static Method Reference 1 2 3 4 Parameter Method Reference Instance Method Reference Constructor Method Reference Interface public interface Display { public int show(String s1, String s2); } Lambda Expression Display disp = String::indexOf;
  • 28. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Method References - Instance Static Method Reference 1 2 3 4 Parameter Method Reference Instance Method Reference Constructor Method Reference Interface public interface Deserializer { public int deserialize(String v1); } Class Lambda Expression public class StringConverter { public int convertToInt(String v1){ return Integer.valueOf(v1); } } StringConverter strConv = new StringConverter(); Deserializer deserializer = strConv::convertToInt;
  • 29. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Method References - Constructor Static Method Reference 1 2 3 4 Parameter Method Reference Instance Method Reference Constructor Method Reference Interface public interface Factory { public String create(char[] val); } Lambda Expression Factory fact = String::new;