SlideShare a Scribd company logo
Lambda Expressions in
Java 8
Presented by:
Isaac Carter
little bit about me..
 Worked for the gov side of life for 4 years with ManTech and
SAIC
 Did it all
 Prior to that I was in the Marines
 got to do a bit of traveling
 Now I work here at 5AM Solutions
 Full stack dev
 Interests as of late…
 Docker
 Linux Mint
 Cloud-computing concepts
Disclaimers
 I love Java, but don’t know everything about
Java…especially Java 8.
 I’m not an expert.
 Feel free to ask any questions at any time. I will do my
best to answer them.
 Any questions that I can’t answer, I promise to research
and respond promptly on the MCJUG forum.
Venkat Subramaniam
 Basis of my talk
 Heard him give a talk
over lambda
expressions in Java 8 at
NFJS conference
 Venkat’s amazon book
list/bio
What I plan to cover…
 Lambda expression syntax
 Iterate through a list
 Transform a list
 Find elements within a list
 Reusing lambda expressions
 Code examples
Is anyone currently using
Java 8?
The good parts of Java 8
 Support for lambda expressions
 New time API
 Collections API has been given a major overhaul
 Functional interfaces
 Default methods
 Concurrency is much easier!!
…and the bad parts of
Java 8
 whyjavasucks.com
 Still no operator overloading
 Haven’t seen this many changes since Java 5
 Lambda expressions
 The code is not directly readable without interpretation
 A developer that reads the code will need to know the
code reasonably well
Java 101
 It’s OO
 Everything is an object
 except primitives!!
 Every class creates instances of objects
 you can’t pass a method as an argument or return a
method body for an instance
 Haskell and Lisp are two good examples of functional
programming languages.
 JavaScript is consider to be one as well. (well actually
both)
Java 8 can now do
functional
programming!!
OO v/s Functional
 Datafields are treated as
objects manipulated through
pre-defined methods
 Terms such as..
 Inheritance
 Polymorphism
 Encapsulation
 Computation as the
evaluation of functions
But that’s really not the
best way to think about
Java 8 and lambdas…
Imperative v/s Declarative
 Telling the machine “HOW”
to do something
 Result = what you wanted to
happen will happen
 Telling the machine “WHAT”
you would like to happen
 Result = let the computer
figure it out
But Isaac we love imperative
programming!
 We are VERY used to describing the “HOW”
 Love controlling everything
 Makes us feel good and comfortable
 Even makes us feel powerful
 Don’t like to leave things up to “magic”
With the power of today’s languages and compilers, we no
longer need to worry about such trivial things
…and this is where lambda expressions come into play…
Some quick syntax before we
look at code…
Syntax of a lambda
expression
 Basic syntax
 (parameters) --> (expression)
 (parameters) --> {statements;}
Examples…
 () --> 5
 takes no value and returns 5
 x --> 2 * x
 takes a number and returns the result of doubling it
 (int x, int y) --> x + y
 takes two integers and returns their sum
 (String s) --> System.out.print(s)
 takes a string and prints it to the console without returning anything
Let’s look at some code
examples
** only look at examples using strings **
.forEach()
Where did .forEach() come
from?
 As of Java 8, the Iterable interface now contains the
.forEach()
 Performs the given action for each element of the
Iterable until all elements have been processed
 Accepts a Consumer type parameter
 Is a Higher Order function
Consumer
What is a Consumer???
 Represents an operation that accepts only one
argument and returns void
 ..is a functional interface
 …and due to this, it can be used as the assignment target
for a lambda expression or method reference
Example…
 Consumer<String> consumer =
(String string) --> (System.out.println(string));
Functional Interface
Functional interface??
 Java already contains the concept of SAM interfaces
 Single Abstract Method interfaces
 Most likely have used them by creating an anonymous inner class
 Examples of use are...Runnable, ActionListener, and Comparator
 So a Functional Interface is the same as a SAM interface
 Java 8 is saying that they can now be represented using lambda
expressions.
 Not going to get into the how’s and why’s of Functional Interfaces
 Such as..
 Not required to use the @FunctionalInterface
 Helps the compiler
 Be kind to your follower developers and use the annotation
Higher Order
Functions
What is a Higher Order
function?
 Means that it is possible to PASS to a method both
values and functions and in the same way the method
itself can return either a value or or a function
 Examples…
 public void doSomething(String name, Function some
Function) {…..}
 public Function createAnAction(Integer someInteger)
{….do some logic and return back a function..}
.stream()
What is .stream() ??
 Not to be confused with InputStream or OutputStream
 In functional programming terms, it’s a “monad”
 Represents a sequence of elements and provides
different kinds of operations to perform computations
upon those elements
 Stream operations are either intermediate or terminal
Predicate
What is a Predicate ?
 A statement that may be true or false depending on the
values of its variables
 Functional interface
 Where would you use a Predicate?
 Anywhere where you need to evaluate a condition on a
group/collection that results in a boolean
So in summary…
 Learn to use lambda expressions
 Let Java do all the work
 Program more declaratively
 Don’t try to customize everything
 Unique time for programming
 Java is no longer just OO
Sources
 Lambda Expressions for Dummies
 Functional Programming in Java: Harnessing the
power of Java 8 Lambda Expresssions
 Java 8 API docs
 Imperative v/s Declarative programming
 Programming Paradigms Wiki
 Start using Java Lambda Expressions
 Java Method Reference
…more sources
 Oracle documentation over lambdas
 Java 8 and Predicates

More Related Content

PPTX
Java 8 Lambda and Streams
Venkata Naga Ravi
 
PPTX
Java 8 lambda
Manav Prasad
 
PDF
Java 8 Lambda Expressions
Scott Leberknight
 
PDF
Lambda Expressions in Java
Erhan Bagdemir
 
PDF
Understanding react hooks
Samundra khatri
 
PDF
JPA and Hibernate
elliando dias
 
PPTX
Constructor in java
Pavith Gunasekara
 
Java 8 Lambda and Streams
Venkata Naga Ravi
 
Java 8 lambda
Manav Prasad
 
Java 8 Lambda Expressions
Scott Leberknight
 
Lambda Expressions in Java
Erhan Bagdemir
 
Understanding react hooks
Samundra khatri
 
JPA and Hibernate
elliando dias
 
Constructor in java
Pavith Gunasekara
 

What's hot (20)

PPT
Tomcat
Venkat Pinagadi
 
PPTX
Hibernate ppt
Aneega
 
PPTX
Java Spring Framework
Mehul Jariwala
 
PPTX
Java 8 - Features Overview
Sergii Stets
 
PDF
Collections In Java
Binoj T E
 
PPT
Java Persistence API (JPA) Step By Step
Guo Albert
 
PDF
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
PDF
Java 8 lambda expressions
Logan Chien
 
PDF
Java 8 features
NexThoughts Technologies
 
PDF
Spring Framework - Core
Dzmitry Naskou
 
PPTX
MULTI THREADING IN JAVA
VINOTH R
 
PPT
Java Collections Framework
Sony India Software Center
 
PPT
Java collections concept
kumar gaurav
 
PPTX
Angular modules in depth
Christoffer Noring
 
PPTX
Introduction to Scala
Mohammad Hossein Rimaz
 
PPT
ASP.NET MVC Presentation
ivpol
 
PPT
Jsp ppt
Vikas Jagtap
 
PDF
Java8 features
Elias Hasnat
 
Hibernate ppt
Aneega
 
Java Spring Framework
Mehul Jariwala
 
Java 8 - Features Overview
Sergii Stets
 
Collections In Java
Binoj T E
 
Java Persistence API (JPA) Step By Step
Guo Albert
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
Java 8 lambda expressions
Logan Chien
 
Java 8 features
NexThoughts Technologies
 
Spring Framework - Core
Dzmitry Naskou
 
MULTI THREADING IN JAVA
VINOTH R
 
Java Collections Framework
Sony India Software Center
 
Java collections concept
kumar gaurav
 
Angular modules in depth
Christoffer Noring
 
Introduction to Scala
Mohammad Hossein Rimaz
 
ASP.NET MVC Presentation
ivpol
 
Jsp ppt
Vikas Jagtap
 
Java8 features
Elias Hasnat
 
Ad

Viewers also liked (11)

PDF
Working With Concurrency In Java 8
Heartin Jacob
 
PDF
Java 9, JShell, and Modularity
Mohammad Hossein Rimaz
 
PDF
Java9 Beyond Modularity - Java 9 más allá de la modularidad
David Gómez García
 
PDF
Java 8 Stream API. A different way to process collections.
David Gómez García
 
PPTX
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Nikita Lipsky
 
PDF
Java SE 9 modules (JPMS) - an introduction
Stephen Colebourne
 
PPT
Java 8 Streams
Manvendra Singh
 
PDF
Java 8 Lambda Expressions & Streams
NewCircle Training
 
PDF
Parallel streams in java 8
David Gómez García
 
PPTX
The do's and don'ts with java 9 (Devoxx 2017)
Robert Scholte
 
PDF
Real World Java 9
Trisha Gee
 
Working With Concurrency In Java 8
Heartin Jacob
 
Java 9, JShell, and Modularity
Mohammad Hossein Rimaz
 
Java9 Beyond Modularity - Java 9 más allá de la modularidad
David Gómez García
 
Java 8 Stream API. A different way to process collections.
David Gómez García
 
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Nikita Lipsky
 
Java SE 9 modules (JPMS) - an introduction
Stephen Colebourne
 
Java 8 Streams
Manvendra Singh
 
Java 8 Lambda Expressions & Streams
NewCircle Training
 
Parallel streams in java 8
David Gómez García
 
The do's and don'ts with java 9 (Devoxx 2017)
Robert Scholte
 
Real World Java 9
Trisha Gee
 
Ad

Similar to Lambda Expressions in Java 8 (20)

PPTX
Functional Programming In Jdk8
Bansilal Haudakari
 
PPT
whats new in java 8
Dori Waldman
 
PDF
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
New York City College of Technology Computer Systems Technology Colloquium
 
PDF
Functional programming in java 8 by harmeet singh
Harmeet Singh(Taara)
 
PPT
Scala Talk at FOSDEM 2009
Martin Odersky
 
PDF
Java 8 Interview Questions and Answers PDF By ScholarHat.pdf
Scholarhat
 
PPTX
Evolve Your Code
RookieOne
 
ODP
Can't Dance The Lambda
Togakangaroo
 
PPTX
Insight into java 1.8, OOP VS FP
Syed Awais Mazhar Bukhari
 
PPTX
A Brief Conceptual Introduction to Functional Java 8 and its API
Jörn Guy Süß JGS
 
PPTX
Java_Interview Qns
ManikandanRamanujam
 
PPTX
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Emiel Paasschens
 
PPT
Framework Design Guidelines
Mohamed Meligy
 
PDF
Principled io in_scala_2019_distribution
Raymond Tay
 
PDF
JavaScript Interview Questions PDF By ScholarHat
Scholarhat
 
PDF
Java basic concept
University of Potsdam
 
PPTX
About Functional Programming
Aapo Kyrölä
 
PDF
Functional programming with Java 8
Talha Ocakçı
 
PDF
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Raffi Khatchadourian
 
PPTX
Software Uni Conf October 2014
Nayden Gochev
 
Functional Programming In Jdk8
Bansilal Haudakari
 
whats new in java 8
Dori Waldman
 
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
New York City College of Technology Computer Systems Technology Colloquium
 
Functional programming in java 8 by harmeet singh
Harmeet Singh(Taara)
 
Scala Talk at FOSDEM 2009
Martin Odersky
 
Java 8 Interview Questions and Answers PDF By ScholarHat.pdf
Scholarhat
 
Evolve Your Code
RookieOne
 
Can't Dance The Lambda
Togakangaroo
 
Insight into java 1.8, OOP VS FP
Syed Awais Mazhar Bukhari
 
A Brief Conceptual Introduction to Functional Java 8 and its API
Jörn Guy Süß JGS
 
Java_Interview Qns
ManikandanRamanujam
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Emiel Paasschens
 
Framework Design Guidelines
Mohamed Meligy
 
Principled io in_scala_2019_distribution
Raymond Tay
 
JavaScript Interview Questions PDF By ScholarHat
Scholarhat
 
Java basic concept
University of Potsdam
 
About Functional Programming
Aapo Kyrölä
 
Functional programming with Java 8
Talha Ocakçı
 
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Raffi Khatchadourian
 
Software Uni Conf October 2014
Nayden Gochev
 

Recently uploaded (20)

PPTX
Materi_Pemrograman_Komputer-Looping.pptx
RanuFajar1
 
PPTX
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
PDF
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pdf
Certivo Inc
 
PDF
Community & News Update Q2 Meet Up 2025
VictoriaMetrics
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
DOCX
The Five Best AI Cover Tools in 2025.docx
aivoicelabofficial
 
PDF
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
PPTX
Save Business Costs with CRM Software for Insurance Agents
Insurance Tech Services
 
PPTX
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
PDF
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PDF
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
DOCX
The Future of Smart Factories Why Embedded Analytics Leads the Way
Varsha Nayak
 
PDF
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
PDF
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
Materi_Pemrograman_Komputer-Looping.pptx
RanuFajar1
 
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pdf
Certivo Inc
 
Community & News Update Q2 Meet Up 2025
VictoriaMetrics
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
The Five Best AI Cover Tools in 2025.docx
aivoicelabofficial
 
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
Save Business Costs with CRM Software for Insurance Agents
Insurance Tech Services
 
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
The Future of Smart Factories Why Embedded Analytics Leads the Way
Varsha Nayak
 
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 

Lambda Expressions in Java 8

  • 1. Lambda Expressions in Java 8 Presented by: Isaac Carter
  • 2. little bit about me..  Worked for the gov side of life for 4 years with ManTech and SAIC  Did it all  Prior to that I was in the Marines  got to do a bit of traveling  Now I work here at 5AM Solutions  Full stack dev  Interests as of late…  Docker  Linux Mint  Cloud-computing concepts
  • 3. Disclaimers  I love Java, but don’t know everything about Java…especially Java 8.  I’m not an expert.  Feel free to ask any questions at any time. I will do my best to answer them.  Any questions that I can’t answer, I promise to research and respond promptly on the MCJUG forum.
  • 4. Venkat Subramaniam  Basis of my talk  Heard him give a talk over lambda expressions in Java 8 at NFJS conference  Venkat’s amazon book list/bio
  • 5. What I plan to cover…  Lambda expression syntax  Iterate through a list  Transform a list  Find elements within a list  Reusing lambda expressions  Code examples
  • 6. Is anyone currently using Java 8?
  • 7. The good parts of Java 8  Support for lambda expressions  New time API  Collections API has been given a major overhaul  Functional interfaces  Default methods  Concurrency is much easier!!
  • 8. …and the bad parts of Java 8  whyjavasucks.com  Still no operator overloading  Haven’t seen this many changes since Java 5  Lambda expressions  The code is not directly readable without interpretation  A developer that reads the code will need to know the code reasonably well
  • 9. Java 101  It’s OO  Everything is an object  except primitives!!  Every class creates instances of objects  you can’t pass a method as an argument or return a method body for an instance  Haskell and Lisp are two good examples of functional programming languages.  JavaScript is consider to be one as well. (well actually both)
  • 10. Java 8 can now do functional programming!!
  • 11. OO v/s Functional  Datafields are treated as objects manipulated through pre-defined methods  Terms such as..  Inheritance  Polymorphism  Encapsulation  Computation as the evaluation of functions
  • 12. But that’s really not the best way to think about Java 8 and lambdas…
  • 13. Imperative v/s Declarative  Telling the machine “HOW” to do something  Result = what you wanted to happen will happen  Telling the machine “WHAT” you would like to happen  Result = let the computer figure it out
  • 14. But Isaac we love imperative programming!  We are VERY used to describing the “HOW”  Love controlling everything  Makes us feel good and comfortable  Even makes us feel powerful  Don’t like to leave things up to “magic” With the power of today’s languages and compilers, we no longer need to worry about such trivial things …and this is where lambda expressions come into play…
  • 15. Some quick syntax before we look at code…
  • 16. Syntax of a lambda expression  Basic syntax  (parameters) --> (expression)  (parameters) --> {statements;} Examples…  () --> 5  takes no value and returns 5  x --> 2 * x  takes a number and returns the result of doubling it  (int x, int y) --> x + y  takes two integers and returns their sum  (String s) --> System.out.print(s)  takes a string and prints it to the console without returning anything
  • 17. Let’s look at some code examples ** only look at examples using strings **
  • 19. Where did .forEach() come from?  As of Java 8, the Iterable interface now contains the .forEach()  Performs the given action for each element of the Iterable until all elements have been processed  Accepts a Consumer type parameter  Is a Higher Order function
  • 21. What is a Consumer???  Represents an operation that accepts only one argument and returns void  ..is a functional interface  …and due to this, it can be used as the assignment target for a lambda expression or method reference Example…  Consumer<String> consumer = (String string) --> (System.out.println(string));
  • 23. Functional interface??  Java already contains the concept of SAM interfaces  Single Abstract Method interfaces  Most likely have used them by creating an anonymous inner class  Examples of use are...Runnable, ActionListener, and Comparator  So a Functional Interface is the same as a SAM interface  Java 8 is saying that they can now be represented using lambda expressions.  Not going to get into the how’s and why’s of Functional Interfaces  Such as..  Not required to use the @FunctionalInterface  Helps the compiler  Be kind to your follower developers and use the annotation
  • 25. What is a Higher Order function?  Means that it is possible to PASS to a method both values and functions and in the same way the method itself can return either a value or or a function  Examples…  public void doSomething(String name, Function some Function) {…..}  public Function createAnAction(Integer someInteger) {….do some logic and return back a function..}
  • 27. What is .stream() ??  Not to be confused with InputStream or OutputStream  In functional programming terms, it’s a “monad”  Represents a sequence of elements and provides different kinds of operations to perform computations upon those elements  Stream operations are either intermediate or terminal
  • 29. What is a Predicate ?  A statement that may be true or false depending on the values of its variables  Functional interface  Where would you use a Predicate?  Anywhere where you need to evaluate a condition on a group/collection that results in a boolean
  • 30. So in summary…  Learn to use lambda expressions  Let Java do all the work  Program more declaratively  Don’t try to customize everything  Unique time for programming  Java is no longer just OO
  • 31. Sources  Lambda Expressions for Dummies  Functional Programming in Java: Harnessing the power of Java 8 Lambda Expresssions  Java 8 API docs  Imperative v/s Declarative programming  Programming Paradigms Wiki  Start using Java Lambda Expressions  Java Method Reference
  • 32. …more sources  Oracle documentation over lambdas  Java 8 and Predicates