SlideShare a Scribd company logo
Lambda expressions
Overview
Yousry Ibrahim
April 27, 2016
Agenda
• What is the meaning of Lambda?
• Functional interface.
• Examples with built-in interfaces.
• Traversing collections with lambda.
• Example with new Interface.
2
What is the meaning of Lambda?
3
–In the computer science lambda means function without a
name.
–So it opens the door to functional programming.
–Lambda let you define a Class with a single method or
function with a special easy syntax.
Functional interface
- In the quote for an early specs for lambda says
“Lambda expressions can only appear in places where they will be assigned to a variable whose
type is a functional interface.”
http://cr.openjdk.java.net/~briangoetz/lambda/lambda-translation.html
- So Functional interfaces are These interfaces which have a single abstract method (before java 8 known
as SAM Single Abstract Method )
- Some examples of Java built-in Functional interfaces :
Runnable, Callable, Comparator, TimerTask
4
Examples with built-in interfaces
5
Runnable Interface:
- Before Java8 we used to make Thread as : - Or even by anonymous class without a name of the class
- we could use the inner classes as :
Examples with built-in interfaces Con.
6
Runnable Interface:
- Using Lambda Expressions with Java8 :
- As you can see the code significantly reduced and also become more readable by using lambda
– Now let me explain the syntax and what happened exactly in the previse example
- In case implementation more than one line
Examples with built-in interfaces Con II.
7
Comparator Interface:
- Before Java8 we used to use Comparator in such way:
Examples with built-in interfaces Con III.
8
Comparator Interface:
- Using Lambda expressions in Java8:
Traversing collections with lambda.
9
- Before Lambda we could traverse collections as below:
Traversing collections with lambda Con.
10
- Lets have a look on Array List Class:
Traversing collections with lambda Con II.
11
- So we can write the previse code using Lambda as below
Example with new Interface.
12
- We not only can used the built-in Interfaces But also can use new Interfaces with below steps:
1- Create your new Functional Interface using new annotation
2- Use your interface with Lambda Expressions:
The result is 50
Thank you
Yousry
13

More Related Content

What's hot (20)

PPT
Loaders and Linkers
kunj desai
 
PPTX
Compilation of c
Way2itech
 
PPT
Consume wsa
mahe797
 
PPT
Compilation
David Halliday
 
PPTX
Linking in MS-Dos System
Satyamevjayte Haxor
 
ODP
Pluggable Pipelines
setitesuk
 
PDF
CNIT 126 Ch 7: Analyzing Malicious Windows Programs
Sam Bowne
 
PPTX
SLF4J+Logback
Guo Albert
 
PDF
Compiler type
Amrish rajput
 
PPTX
SLF4J Explained........
Sunitha Satyadas
 
PDF
loaders and linkers
Temesgen Molla
 
PPT
Test
rebelvenky1
 
PPT
SLF4J (Simple Logging Facade for Java)
Guo Albert
 
PPTX
The Java Story
David Parsons
 
PPTX
Introduction To Rmi
SwarupKulkarni
 
PDF
Compilation and Execution
Chong-Kuan Chen
 
PPTX
New Features of JAVA SE8
Dinesh Pathak
 
PDF
MuleSoft Surat Virtual Meetup#30 - Flat File Schemas Transformation With Mule...
Jitendra Bafna
 
PPT
How a Compiler Works ?
Hirdesh Vishwdewa
 
PPT
Byte code jvm
myrajendra
 
Loaders and Linkers
kunj desai
 
Compilation of c
Way2itech
 
Consume wsa
mahe797
 
Compilation
David Halliday
 
Linking in MS-Dos System
Satyamevjayte Haxor
 
Pluggable Pipelines
setitesuk
 
CNIT 126 Ch 7: Analyzing Malicious Windows Programs
Sam Bowne
 
SLF4J+Logback
Guo Albert
 
Compiler type
Amrish rajput
 
SLF4J Explained........
Sunitha Satyadas
 
loaders and linkers
Temesgen Molla
 
SLF4J (Simple Logging Facade for Java)
Guo Albert
 
The Java Story
David Parsons
 
Introduction To Rmi
SwarupKulkarni
 
Compilation and Execution
Chong-Kuan Chen
 
New Features of JAVA SE8
Dinesh Pathak
 
MuleSoft Surat Virtual Meetup#30 - Flat File Schemas Transformation With Mule...
Jitendra Bafna
 
How a Compiler Works ?
Hirdesh Vishwdewa
 
Byte code jvm
myrajendra
 

Viewers also liked (20)

ODP
Java8 Lambda and Streams
Mindfire Solutions
 
PPTX
Exploring Streams and Lambdas in Java8
Isuru Samaraweera
 
PDF
Java8
Sunil Kumar
 
PDF
Scala is java8.next()
daewon jeong
 
PDF
Why is Java relevant? New features of Java8
xshyamx
 
PPTX
Java8: what's new and what's hot
Sergii Maliarov
 
PDF
Java8 Neue Sprachfeatures - Lambda/Streams/default Methods/FunctionalInterfaces
Dirk Detering
 
PPTX
Java8
Jadson Santos
 
PDF
2014 java functional
Demian Neidetcher
 
PPTX
Introduction to functional programming with java 8
JavaBrahman
 
PDF
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
Ruslan Shevchenko
 
PPTX
Java8 and Functional Programming
Yiguang Hu
 
PDF
Java8 features
Elias Hasnat
 
PPTX
Java8 training - Class 1
Marut Singh
 
PDF
Functional Java 8 in everyday life
Andrea Iacono
 
PPTX
Java8 training - class 2
Marut Singh
 
PPTX
Java8 training - class 3
Marut Singh
 
PPT
Java8 - Under the hood
Lakshmi Narasimhan
 
PPTX
A Quick peek @ New Date & Time API of Java 8
Buddha Jyothiprasad
 
PDF
Java8
Freeman Zhang
 
Java8 Lambda and Streams
Mindfire Solutions
 
Exploring Streams and Lambdas in Java8
Isuru Samaraweera
 
Scala is java8.next()
daewon jeong
 
Why is Java relevant? New features of Java8
xshyamx
 
Java8: what's new and what's hot
Sergii Maliarov
 
Java8 Neue Sprachfeatures - Lambda/Streams/default Methods/FunctionalInterfaces
Dirk Detering
 
2014 java functional
Demian Neidetcher
 
Introduction to functional programming with java 8
JavaBrahman
 
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
Ruslan Shevchenko
 
Java8 and Functional Programming
Yiguang Hu
 
Java8 features
Elias Hasnat
 
Java8 training - Class 1
Marut Singh
 
Functional Java 8 in everyday life
Andrea Iacono
 
Java8 training - class 2
Marut Singh
 
Java8 training - class 3
Marut Singh
 
Java8 - Under the hood
Lakshmi Narasimhan
 
A Quick peek @ New Date & Time API of Java 8
Buddha Jyothiprasad
 
Ad

Similar to Lambda expressions java8 - yousry (20)

PPTX
Insight into java 1.8, OOP VS FP
Syed Awais Mazhar Bukhari
 
PDF
Java8 features
Minal Maniar
 
PDF
Java 8-revealed
Hamed Hatami
 
PPTX
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Emiel Paasschens
 
PPTX
Java 8 - An Overview
Indrajit Das
 
PDF
Eclipse and Java 8 - Eclipse Day India 2013
Noopur Gupta
 
PDF
Functional programming in java 8 by harmeet singh
Harmeet Singh(Taara)
 
PPTX
Functional Interfaces and Method References.pptx
MuhammadSalman701062
 
PPTX
Week-1..................................
kmjanani05
 
PPTX
Java 8 - Features Overview
Sergii Stets
 
PPTX
Lambdas, Collections Framework, Stream API
Prabu U
 
PDF
Java 8 Lambda Expressions & Streams
NewCircle Training
 
PPTX
Java 8 lambdas expressions
Lars Lemos
 
PDF
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
Coen De Roover
 
PPTX
Functional Programming In Jdk8
Bansilal Haudakari
 
PPTX
Lambda Expressions Java 8 Features usage
AsmaShaikh478737
 
PDF
New c sharp3_features_(linq)_part_ii
Nico Ludwig
 
PPTX
Java Advanced Topic - Java Lambda Expressions.pptx
MuraliD32
 
DOCX
Colloquium Report
Mohammad Faizan
 
PDF
Smart Migration to JDK 8
Geertjan Wielenga
 
Insight into java 1.8, OOP VS FP
Syed Awais Mazhar Bukhari
 
Java8 features
Minal Maniar
 
Java 8-revealed
Hamed Hatami
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Emiel Paasschens
 
Java 8 - An Overview
Indrajit Das
 
Eclipse and Java 8 - Eclipse Day India 2013
Noopur Gupta
 
Functional programming in java 8 by harmeet singh
Harmeet Singh(Taara)
 
Functional Interfaces and Method References.pptx
MuhammadSalman701062
 
Week-1..................................
kmjanani05
 
Java 8 - Features Overview
Sergii Stets
 
Lambdas, Collections Framework, Stream API
Prabu U
 
Java 8 Lambda Expressions & Streams
NewCircle Training
 
Java 8 lambdas expressions
Lars Lemos
 
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
Coen De Roover
 
Functional Programming In Jdk8
Bansilal Haudakari
 
Lambda Expressions Java 8 Features usage
AsmaShaikh478737
 
New c sharp3_features_(linq)_part_ii
Nico Ludwig
 
Java Advanced Topic - Java Lambda Expressions.pptx
MuraliD32
 
Colloquium Report
Mohammad Faizan
 
Smart Migration to JDK 8
Geertjan Wielenga
 
Ad

Recently uploaded (20)

PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 

Lambda expressions java8 - yousry

  • 2. Agenda • What is the meaning of Lambda? • Functional interface. • Examples with built-in interfaces. • Traversing collections with lambda. • Example with new Interface. 2
  • 3. What is the meaning of Lambda? 3 –In the computer science lambda means function without a name. –So it opens the door to functional programming. –Lambda let you define a Class with a single method or function with a special easy syntax.
  • 4. Functional interface - In the quote for an early specs for lambda says “Lambda expressions can only appear in places where they will be assigned to a variable whose type is a functional interface.” http://cr.openjdk.java.net/~briangoetz/lambda/lambda-translation.html - So Functional interfaces are These interfaces which have a single abstract method (before java 8 known as SAM Single Abstract Method ) - Some examples of Java built-in Functional interfaces : Runnable, Callable, Comparator, TimerTask 4
  • 5. Examples with built-in interfaces 5 Runnable Interface: - Before Java8 we used to make Thread as : - Or even by anonymous class without a name of the class - we could use the inner classes as :
  • 6. Examples with built-in interfaces Con. 6 Runnable Interface: - Using Lambda Expressions with Java8 : - As you can see the code significantly reduced and also become more readable by using lambda – Now let me explain the syntax and what happened exactly in the previse example - In case implementation more than one line
  • 7. Examples with built-in interfaces Con II. 7 Comparator Interface: - Before Java8 we used to use Comparator in such way:
  • 8. Examples with built-in interfaces Con III. 8 Comparator Interface: - Using Lambda expressions in Java8:
  • 9. Traversing collections with lambda. 9 - Before Lambda we could traverse collections as below:
  • 10. Traversing collections with lambda Con. 10 - Lets have a look on Array List Class:
  • 11. Traversing collections with lambda Con II. 11 - So we can write the previse code using Lambda as below
  • 12. Example with new Interface. 12 - We not only can used the built-in Interfaces But also can use new Interfaces with below steps: 1- Create your new Functional Interface using new annotation 2- Use your interface with Lambda Expressions: The result is 50

Editor's Notes

  • #2: This is a sample Title Slide with Picture ideal for including a dark picture with a brief title and subtitle. A selection of pre-approved title slides are available in the HPE Title Slide Library. The location of the library will be communicated later. To insert a slide with a different picture from the HPE Title Slide Library: Open the file HPE_16x9_Title_Slide_Library.pptx From the Slide thumbnails pane, select the slide with the picture you would like to use in your presentation and click Copy (Ctrl+C) Open a copy of the new HPE 16x9 template (Standard or Events) or your current presentation In the Slide thumbnails pane, click Paste (Ctrl+V) A Paste Options clipboard icon will appear. Click the icon and select Keep Source Formatting. (Ctrl+K)
  • #7: Method Signature ()  Which is empty without arguments because our method in this case (run) does not accept arguments, but in case we implement method that accept arguments we would give here arguments names without types because of course the interface as we said has only one method and they types are already known and lambda target is to eliminate the unnecessary syntax .   The second part is the implementation of the method body