SlideShare a Scribd company logo
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

Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
Manav Prasad
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
Jeevesh Pandey
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
Rohit Verma
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features Overview
Sergii Stets
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
Hitesh-Java
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
Sanjoy Kumar Roy
 
Spring Core
Spring CoreSpring Core
Spring Core
Pushan Bhattacharya
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepGuo Albert
 
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Edureka!
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
Erhan Bagdemir
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
tola99
 
Java Basics
Java BasicsJava Basics
Java Basics
shivamgarg_nitj
 
Wrapper classes
Wrapper classes Wrapper classes
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
Ganesh Samarthyam
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
Hitesh Kumar
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
Logan Chien
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
Manav Prasad
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
Introduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionIntroduction to Spring's Dependency Injection
Introduction to Spring's Dependency Injection
Richard Paul
 

What's hot (20)

Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features Overview
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
 
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
 
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
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
 
Introduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionIntroduction to Spring's Dependency Injection
Introduction to Spring's Dependency Injection
 

Similar to 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 I
Roan 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 expressions
Lars Lemos
 
Java8 features
Java8 featuresJava8 features
Java8 features
Minal Maniar
 
What's new in java 8
What's new in java 8What's new in java 8
What's new in java 8
Dian Aditya
 
Cs30 New
Cs30 NewCs30 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
Eclipse 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 Streams
Emiel Paasschens
 
Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3
Simon Ritter
 
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
Fulvio 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 singh
Harmeet 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 JDK8
IndicThreads
 
Java RMI
Java RMIJava RMI
Java RMI
Ankit Desai
 
imperative programming language, java, android
imperative programming language, java, androidimperative programming language, java, android
imperative programming language, java, android
i i
 
Java 8
Java 8Java 8
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
Ahmed mar3y
 
使用 AWS 無伺服器化應用程式模型 (SAM) 釋放您的 "敏捷" 能量 (Level 300)
使用 AWS 無伺服器化應用程式模型 (SAM) 釋放您的 "敏捷" 能量 (Level 300)使用 AWS 無伺服器化應用程式模型 (SAM) 釋放您的 "敏捷" 能量 (Level 300)
使用 AWS 無伺服器化應用程式模型 (SAM) 釋放您的 "敏捷" 能量 (Level 300)
Amazon Web Services
 
Functional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritterFunctional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritter
Simon Ritter
 

Similar to 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
 
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)
 
Functional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritterFunctional programming with_jdk8-s_ritter
Functional programming with_jdk8-s_ritter
 

More from 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!
 

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
 
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
 

Recently uploaded

Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 

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;