SlideShare una empresa de Scribd logo
1 de 30
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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional Interfaces
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
JavaFX Overview
JavaFX OverviewJavaFX Overview
JavaFX Overview
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Hibernate
HibernateHibernate
Hibernate
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for Beginners
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features Overview
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Java 8 Default Methods
Java 8 Default MethodsJava 8 Default Methods
Java 8 Default Methods
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 

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

Java moderno java para Jedis episodio I
Java moderno  java para  Jedis  episodio IJava moderno  java para  Jedis  episodio I
Java moderno java para Jedis episodio IRoan Brasil Monteiro
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Java 8 lambdas expressions
Java 8 lambdas expressionsJava 8 lambdas expressions
Java 8 lambdas expressionsLars Lemos
 
What's new in java 8
What's new in java 8What's new in java 8
What's new in java 8Dian Aditya
 
Eclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 OverviewEclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 OverviewEclipse Day India
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsEmiel Paasschens
 
Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3Simon Ritter
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentationVan Huong
 
Introduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsIntroduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsFulvio Corno
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhHarmeet Singh(Taara)
 
Functional Programming With Lambdas and Streams in JDK8
 Functional Programming With Lambdas and Streams in JDK8 Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8IndicThreads
 
imperative programming language, java, android
imperative programming language, java, androidimperative programming language, java, android
imperative programming language, java, androidi i
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 itiAhmed mar3y
 
使用 AWS 無伺服器化應用程式模型 (SAM) 釋放您的 "敏捷" 能量 (Level 300)
使用 AWS 無伺服器化應用程式模型 (SAM) 釋放您的 "敏捷" 能量 (Level 300)使用 AWS 無伺服器化應用程式模型 (SAM) 釋放您的 "敏捷" 能量 (Level 300)
使用 AWS 無伺服器化應用程式模型 (SAM) 釋放您的 "敏捷" 能量 (Level 300)Amazon Web Services
 

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

Java moderno java para Jedis episodio I
Java moderno  java para  Jedis  episodio IJava moderno  java para  Jedis  episodio I
Java moderno java para Jedis episodio I
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java 8 lambdas expressions
Java 8 lambdas expressionsJava 8 lambdas expressions
Java 8 lambdas expressions
 
Java8 features
Java8 featuresJava8 features
Java8 features
 
What's new in java 8
What's new in java 8What's new in java 8
What's new in java 8
 
Cs30 New
Cs30 NewCs30 New
Cs30 New
 
Eclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 OverviewEclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 Overview
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
 
Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 
Introduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsIntroduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applications
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singh
 
Functional Programming With Lambdas and Streams in JDK8
 Functional Programming With Lambdas and Streams in JDK8 Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8
 
Java RMI
Java RMIJava RMI
Java RMI
 
imperative programming language, java, android
imperative programming language, java, androidimperative programming language, java, android
imperative programming language, java, android
 
Java 8
Java 8Java 8
Java 8
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
使用 AWS 無伺服器化應用程式模型 (SAM) 釋放您的 "敏捷" 能量 (Level 300)
使用 AWS 無伺服器化應用程式模型 (SAM) 釋放您的 "敏捷" 能量 (Level 300)使用 AWS 無伺服器化應用程式模型 (SAM) 釋放您的 "敏捷" 能量 (Level 300)
使用 AWS 無伺服器化應用程式模型 (SAM) 釋放您的 "敏捷" 能量 (Level 300)
 

Más de 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 | EdurekaEdureka!
 
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 | EdurekaEdureka!
 
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 | EdurekaEdureka!
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaEdureka!
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaEdureka!
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaEdureka!
 
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 | EdurekaEdureka!
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaEdureka!
 
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| EdurekaEdureka!
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaEdureka!
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | EdurekaEdureka!
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEdureka!
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEdureka!
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaEdureka!
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaEdureka!
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaEdureka!
 
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 | EdurekaEdureka!
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaEdureka!
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | EdurekaEdureka!
 

Más de 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
 
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
 
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
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | 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
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | 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
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | 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
 
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
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

Último

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Último (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

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

  • 1.
  • 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;