SlideShare a Scribd company logo
first taste of Java 8 
Sunil Kumar | Wiley London | 22-01-2014
Java 8 features 
● Lambda 
● Interface improvement 
● Streams 
● new packages 
Keywords : Big data, Parallelism, Cloud computing
1. Lambda (anonymous function) 
In mathematics and computing generally, a lambda expression is a function: for some 
or all combinations of input values it specifies an output value. Lambda expressions in 
Java introduce the idea of functions into the language 
Ex: 0 param 
Runnable r = () -> System.out.println("hello world"); 
r.run(); // prints "hello world" 
Object o = () -> System.out.println("hello world"); //won’t compile 
Ex: 1 param 
FileFilter filter = f -> f.getAbsolutePath().endsWith(".txt"); 
return filter.accept(new File("myfile.txt")); // returns true
Lambda - syntax 
Lambda expression has three part : parenthesized params, arrow and body 
● (parameters) -> expression 
● (parameters) -> {statements…} 
Type inference 
Comparator<String> c = (lhs, rhs) -> { 
System.out.println("comparing : " + lhs + " to " + rhs); 
return lhs.compareTo(rhs); 
}; 
int result = c.compare(“hello”, “world”)
More examples 
List<Apple> inventory = Arrays.asList(new Apple(80,"green"), 
new Apple(155, "green"), 
new Apple(120, "red")); 
// [Apple{color='green', weight=80}, Apple{color='green', weight=155}] 
List<Apple> greenApples2 = filterApples(inventory, (Apple a) -> "green".equals(a.getColor())); 
System.out.println(greenApples2); 
// [Apple{color='green', weight=155}] 
List<Apple> heavyApples2 = filterApples(inventory, (Apple a) -> a.getWeight() > 150); 
System.out.println(heavyApples2); 
public static List<Apple> filterApples(List<Apple> inventory, Predicate<Apple> p){ 
List<Apple> result = new ArrayList<>(); 
for(Apple apple : inventory){ 
if(p.test(apple)){ 
result.add(apple); 
}} 
return result; 
}
Method References 
Method references are compact lambda expressions for methods that already have a 
name. 
● String::valueOf x -> String.valueOf(x) 
● Object::toString x -> x.toString() 
● x::toString () -> x.toString() 
● ArrayList::new () -> new ArrayList<>()
2. Interface improvement 
(Functional interface) 
A functional interface is one whose type can be used for a method parameter when a lambda is to 
be supplied as the actual argument. 
For example, the forEach method on collections could have the following signature: 
public void forEach(Consumer<? super T> consumer); 
More precisely, a functional interface is defined as any interface that has exactly one explicitly 
declared abstract method. 
● interface can now define static methods. 
● interfaces can now provide default methods 
(The qualification is necessary because an interface may have non-abstract default methods.) This 
is why functional interfaces used to be called Single Abstract Method (SAM) interfaces, a term 
that is still sometimes seen.
3. Streams 
A stream is a sequence of values. Allows functional-style operations on streams of 
values. 
Stream<T> stream = collection.stream(); 
Stream<T> stream = collection.parallelStream();
Steams type 
Operations Interface Used lambda signature return type return value 
Sample lazy/intermediate operations 
filter Predicate<T> T -> boolean Stream<T> stream containing input 
elements that satisfy the 
Predicate 
map Function<T, R> T -> R Stream<R> stream of values, the result 
of applying the Function to 
each input element 
sorted Comparator<T> (T, T) -> int Stream<T> stream containing the input 
elements, sorted by the 
Comparator 
Sample eagar/terminal operation 
reduce BinaryOperator<T> (T, T) -> T Optional<T> 
forEach Consumer<T> T -> void void
4. java.util.function 
Function<T, R> - take T as input, return R as output 
Predicate<T> - take T as input, return a boolean as output 
Consumer<T> - take T as input, don't return anything 
Supplier<T> - take no input, return T 
BinaryOperator<T> - take two T's as input, return one T as output
Thank You. 
Q & A.
Reference: 
● http://www.lambdafaq.org/ 
● http://www.infoq.com/news/2013/08/everything-about-java-8 
● https://blogs.oracle.com/thejavatutorials/entry/jdk_8_documentation_developer_preview 
● http://sett.ociweb.com/sett/settFeb2013.html 
● http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html 
● https://github.com/java8/LambdasInAction

More Related Content

What's hot (20)

PPTX
operator overloading
Sorath Peetamber
 
PDF
Functional programming java
Maneesh Chaturvedi
 
PDF
Functional Programming in JavaScript
Will Livengood
 
PPTX
Working with functions in matlab
harman kaur
 
PPTX
User defined Functions in MATLAB Part 1
Shameer Ahmed Koya
 
PDF
Functional programming 101
Maneesh Chaturvedi
 
PPT
Reactive cocoa
gillygize
 
PPT
Functions
Online
 
PPT
Inroduction to r
manikanta361
 
PPTX
Operator overloading
Garima Singh Makhija
 
PPTX
Parameter passing to_functions_in_c
ForwardBlog Enewzletter
 
PPTX
java8
Arik Abulafya
 
PPTX
Operator overloading
Kumar
 
PPTX
R: Apply Functions
DataminingTools Inc
 
PPT
08 c++ Operator Overloading.ppt
Tareq Hasan
 
PDF
M11 operator overloading and type conversion
NabeelaNousheen
 
PPT
Unit 3 stack
kalyanineve
 
PPT
Operator overloading
Northeastern University
 
PDF
Java8
Felipe Mamud
 
DOCX
C programming language working with functions 1
Jeevan Raj
 
operator overloading
Sorath Peetamber
 
Functional programming java
Maneesh Chaturvedi
 
Functional Programming in JavaScript
Will Livengood
 
Working with functions in matlab
harman kaur
 
User defined Functions in MATLAB Part 1
Shameer Ahmed Koya
 
Functional programming 101
Maneesh Chaturvedi
 
Reactive cocoa
gillygize
 
Functions
Online
 
Inroduction to r
manikanta361
 
Operator overloading
Garima Singh Makhija
 
Parameter passing to_functions_in_c
ForwardBlog Enewzletter
 
Operator overloading
Kumar
 
R: Apply Functions
DataminingTools Inc
 
08 c++ Operator Overloading.ppt
Tareq Hasan
 
M11 operator overloading and type conversion
NabeelaNousheen
 
Unit 3 stack
kalyanineve
 
Operator overloading
Northeastern University
 
C programming language working with functions 1
Jeevan Raj
 

Viewers also liked (7)

PPTX
Java SE 8 - New Features
Naveen Hegde
 
PPTX
Java 8 - Features Overview
Sergii Stets
 
PDF
Java8 features
Elias Hasnat
 
PDF
Java 8 - project lambda
Ivar Østhus
 
PPTX
Java 8 Features
Leninkumar Koppoju
 
PPTX
Java 8 presentation
Van Huong
 
PPTX
New Features in JDK 8
Martin Toshev
 
Java SE 8 - New Features
Naveen Hegde
 
Java 8 - Features Overview
Sergii Stets
 
Java8 features
Elias Hasnat
 
Java 8 - project lambda
Ivar Østhus
 
Java 8 Features
Leninkumar Koppoju
 
Java 8 presentation
Van Huong
 
New Features in JDK 8
Martin Toshev
 
Ad

Similar to Java8 (20)

PPTX
Java8 training - Class 1
Marut Singh
 
PPTX
Week-1..................................
kmjanani05
 
PPTX
FUNctional Programming in Java 8
Richard Walker
 
PPTX
java150929145120-lva1-app6892 (2).pptx
BruceLee275640
 
PPTX
Java 8 new features
Aniket Thakur
 
PPTX
Java 8 Intro - Core Features
GlobalLogic Ukraine
 
PDF
Lambda Functions in Java 8
Ganesh Samarthyam
 
PPTX
New features in jdk8 iti
Ahmed mar3y
 
PDF
Java 8 features
NexThoughts Technologies
 
PPTX
Java 8
vpulec
 
PDF
Java SE 8 library design
Stephen Colebourne
 
PPT
Major Java 8 features
Sanjoy Kumar Roy
 
ODP
Introduction to Java 8
Knoldus Inc.
 
PPTX
Project Lambda: Evolution of Java
Can Pekdemir
 
PPTX
Java SE 8
Murali Pachiyappan
 
PDF
Java 8 Interview Questions and Answers PDF By ScholarHat.pdf
Scholarhat
 
PPTX
Java 8 - An Overview
Indrajit Das
 
PDF
Java 8 by example!
Mark Harrison
 
PPTX
Java8lambda
Isuru Samaraweera
 
PDF
Java8
Freeman Zhang
 
Java8 training - Class 1
Marut Singh
 
Week-1..................................
kmjanani05
 
FUNctional Programming in Java 8
Richard Walker
 
java150929145120-lva1-app6892 (2).pptx
BruceLee275640
 
Java 8 new features
Aniket Thakur
 
Java 8 Intro - Core Features
GlobalLogic Ukraine
 
Lambda Functions in Java 8
Ganesh Samarthyam
 
New features in jdk8 iti
Ahmed mar3y
 
Java 8 features
NexThoughts Technologies
 
Java 8
vpulec
 
Java SE 8 library design
Stephen Colebourne
 
Major Java 8 features
Sanjoy Kumar Roy
 
Introduction to Java 8
Knoldus Inc.
 
Project Lambda: Evolution of Java
Can Pekdemir
 
Java 8 Interview Questions and Answers PDF By ScholarHat.pdf
Scholarhat
 
Java 8 - An Overview
Indrajit Das
 
Java 8 by example!
Mark Harrison
 
Java8lambda
Isuru Samaraweera
 
Ad

Recently uploaded (20)

PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 

Java8

  • 1. first taste of Java 8 Sunil Kumar | Wiley London | 22-01-2014
  • 2. Java 8 features ● Lambda ● Interface improvement ● Streams ● new packages Keywords : Big data, Parallelism, Cloud computing
  • 3. 1. Lambda (anonymous function) In mathematics and computing generally, a lambda expression is a function: for some or all combinations of input values it specifies an output value. Lambda expressions in Java introduce the idea of functions into the language Ex: 0 param Runnable r = () -> System.out.println("hello world"); r.run(); // prints "hello world" Object o = () -> System.out.println("hello world"); //won’t compile Ex: 1 param FileFilter filter = f -> f.getAbsolutePath().endsWith(".txt"); return filter.accept(new File("myfile.txt")); // returns true
  • 4. Lambda - syntax Lambda expression has three part : parenthesized params, arrow and body ● (parameters) -> expression ● (parameters) -> {statements…} Type inference Comparator<String> c = (lhs, rhs) -> { System.out.println("comparing : " + lhs + " to " + rhs); return lhs.compareTo(rhs); }; int result = c.compare(“hello”, “world”)
  • 5. More examples List<Apple> inventory = Arrays.asList(new Apple(80,"green"), new Apple(155, "green"), new Apple(120, "red")); // [Apple{color='green', weight=80}, Apple{color='green', weight=155}] List<Apple> greenApples2 = filterApples(inventory, (Apple a) -> "green".equals(a.getColor())); System.out.println(greenApples2); // [Apple{color='green', weight=155}] List<Apple> heavyApples2 = filterApples(inventory, (Apple a) -> a.getWeight() > 150); System.out.println(heavyApples2); public static List<Apple> filterApples(List<Apple> inventory, Predicate<Apple> p){ List<Apple> result = new ArrayList<>(); for(Apple apple : inventory){ if(p.test(apple)){ result.add(apple); }} return result; }
  • 6. Method References Method references are compact lambda expressions for methods that already have a name. ● String::valueOf x -> String.valueOf(x) ● Object::toString x -> x.toString() ● x::toString () -> x.toString() ● ArrayList::new () -> new ArrayList<>()
  • 7. 2. Interface improvement (Functional interface) A functional interface is one whose type can be used for a method parameter when a lambda is to be supplied as the actual argument. For example, the forEach method on collections could have the following signature: public void forEach(Consumer<? super T> consumer); More precisely, a functional interface is defined as any interface that has exactly one explicitly declared abstract method. ● interface can now define static methods. ● interfaces can now provide default methods (The qualification is necessary because an interface may have non-abstract default methods.) This is why functional interfaces used to be called Single Abstract Method (SAM) interfaces, a term that is still sometimes seen.
  • 8. 3. Streams A stream is a sequence of values. Allows functional-style operations on streams of values. Stream<T> stream = collection.stream(); Stream<T> stream = collection.parallelStream();
  • 9. Steams type Operations Interface Used lambda signature return type return value Sample lazy/intermediate operations filter Predicate<T> T -> boolean Stream<T> stream containing input elements that satisfy the Predicate map Function<T, R> T -> R Stream<R> stream of values, the result of applying the Function to each input element sorted Comparator<T> (T, T) -> int Stream<T> stream containing the input elements, sorted by the Comparator Sample eagar/terminal operation reduce BinaryOperator<T> (T, T) -> T Optional<T> forEach Consumer<T> T -> void void
  • 10. 4. java.util.function Function<T, R> - take T as input, return R as output Predicate<T> - take T as input, return a boolean as output Consumer<T> - take T as input, don't return anything Supplier<T> - take no input, return T BinaryOperator<T> - take two T's as input, return one T as output
  • 11. Thank You. Q & A.
  • 12. Reference: ● http://www.lambdafaq.org/ ● http://www.infoq.com/news/2013/08/everything-about-java-8 ● https://blogs.oracle.com/thejavatutorials/entry/jdk_8_documentation_developer_preview ● http://sett.ociweb.com/sett/settFeb2013.html ● http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html ● https://github.com/java8/LambdasInAction