SlideShare a Scribd company logo
INTRO TO JAVA 8
SHIJIE ZHANG
OUTLINE
▸What will Java 8 give us
▸Behavior parameterization
▸More comprehensive functional interface
▸Lambda expression
▸Method reference
▸Simple syntactic sugar - new methods inside Collections
▸Functional programming - Stream API
▸Intuition
▸Intermediate and terminal operations
▸Properties
▸Alternative to NULL — Optional
▸Changeable Interface — Default methods
▸Asynchronous programming enhancement - Future vs CompletableFuture
▸Other features
▸Dark side of Java 8
▸Conclusion
WHAT WILL JAVA 8 BRING US
CLIMATE IS CHANGING
▸ Java was in dominant positions due to its
simplicity, portability, safety and free to use.
▸ JVM-based dynamic language comes up,
known for their simplicity and portability.
(Groovy, Clojure, Scala)
▸ Big data is on the rise. Programmers need
to deal with large collections.
▸ Multicore processor is becoming more and
more popular. Programmers need to an
easier way to do parallel programming.
▸ Java is kind of verbose.
WHAT WILL JAVA 8 BRING US
OUTLINE
▸What will Java 8 give us
▸Behavior parameterization
▸More comprehensive functional interface
▸Lambda expression
▸Method reference
▸Simple syntactic sugar - new methods inside Collections
▸Functional programming - Stream API
▸Intuition
▸Intermediate and terminal operations
▸Properties
▸Alternative to NULL — Optional
▸Changeable Interface — Default methods
▸Asynchronous programming enhancement - Future vs CompletableFuture
▸Other features
▸Dark side of Java 8
▸Conclusion
OUTLINE
▸What will Java 8 give us
▸Behavior parameterization
▸More comprehensive functional interface
▸Lambda expression
▸Method reference
▸Simple syntactic sugar - new methods inside Collections
▸Functional programming - Stream API
▸Intuition
▸Intermediate and terminal operations
▸Properties
▸Alternative to NULL — Optional
▸Changeable Interface — Default methods
▸Asynchronous programming enhancement - Future vs CompletableFuture
▸Other features
▸Dark side of Java 8
▸Conclusion
BEHAVIOR PARAMETERIZATION - LAMBDAS
More comprehensive functional interface
▸ Comparator is an interface. More exactly, a functional interface.
BEHAVIOR PARAMETERIZATION - LAMBDAS
More comprehensive functional interface
▸ Functional interface: an interface has exactly one abstract method
▸ Several functional interface exists before Java 8
▸ Functional interface enables behavior parameterization
BEHAVIOR PARAMETERIZATION - LAMBDAS
BEHAVIOR PARAMETERIZATION - LAMBDAS
Where to use functional interface
▸ Anywhere an object could be used
▸ method arguments/parameters/return types
▸ inside collections
▸ Variables
▸ …….
BEHAVIOR PARAMETERIZATION - LAMBDAS
In the past, use anonymous class as instance for functional interface
Now, use lambda expression/method reference as instance for functional interface
▸ Think about Comparator — create an anonymous class
▸ All anonymous class could be replaced with lambda/method reference
▸ Anonymous class ~ lambda expression ~ method reference
▸ lambda expressions
▸ method reference
OUTLINE
▸What will Java 8 give us
▸Behavior parameterization
▸More comprehensive functional interface
▸Lambda expression
▸Method reference
▸Simple syntactic sugar - new methods inside Collections
▸Functional programming - Stream API
▸Intuition
▸Intermediate and terminal operations
▸Properties
▸Alternative to NULL — Optional
▸Changeable Interface — Default methods
▸Asynchronous programming enhancement - Future vs CompletableFuture
▸Other features
▸Dark side of Java 8
▸Conclusion
BEHAVIOR PARAMETERIZATION - LAMBDAS
Lambdas definition
▸ Definition
▸ Examples:
1. ( ) -> { }
2. ( ) -> “Raoul”
3. ( ) -> { return “Mario”;}
4. ( Integer i ) -> return “Alan” + i;
5. ( String s ) -> { “Iron Man”; }
BEHAVIOR PARAMETERIZATION - LAMBDAS
Lambdas definition
▸ Definition
▸ Examples:
1. ( ) -> { }
2. ( ) -> “Raoul”
3. ( ) -> { return “Mario”;}
4. ( Integer i ) -> return “Alan” + i;
5. ( String s ) -> { “Iron Man”; }
BEHAVIOR PARAMETERIZATION - LAMBDAS
Lambda use cases - whenever you use anonymous class
BEHAVIOR PARAMETERIZATION - LAMBDAS
BEHAVIOR PARAMETERIZATION - LAMBDAS
Type reference
Restriction on local variables
▸ Definition
OUTLINE
▸What will Java 8 give us
▸Behavior parameterization
▸More comprehensive functional interface
▸Lambda expression
▸Method reference
▸Simple syntactic sugar - new methods inside Collections
▸Functional programming - Stream API
▸Intuition
▸Intermediate and terminal operations
▸Properties
▸Alternative to NULL — Optional
▸Changeable Interface — Default methods
▸Asynchronous programming enhancement - Future vs CompletableFuture
▸Other features
▸Dark side of Java 8
▸Conclusion
BEHAVIOR PARAMETERIZATION - LAMBDAS
Method reference definition
▸ Definition: syntactic sugar for lambda expressions
BEHAVIOR PARAMETERIZATION - LAMBDAS
Rules for converting lambda to method reference
▸ A method reference to a static method
▸ A method reference to an instance method of an arbitrary type
▸ A method reference to an instance method of an existing object
OUTLINE
▸What will Java 8 give us
▸Behavior parameterization
▸More comprehensive functional interface
▸Lambda expression
▸Method reference
▸Simple syntactic sugar - new methods inside Collections
▸Functional programming - Stream API
▸Intuition
▸Intermediate and terminal operations
▸Properties
▸Alternative to NULL — Optional
▸Changeable Interface — Default methods
▸Asynchronous programming enhancement - Future vs CompletableFuture
▸Other features
▸Dark side of Java 8
▸Conclusion
SIMPLE SYNTACTIC SUGAR - NEW METHODS INSIDE COLLECTIONS
Map interface: getOrDefault method
▸ Definition: getOrDefault(K key, V defaultValue)
▸ Scenario: get a value (may not exist) from a map, do some calculation and put it back
SIMPLE SYNTACTIC SUGAR - NEW METHODS INSIDE COLLECTIONS
Map interface: computeIfAbsent method
▸ Definition: computeIfAbsent(K key, Function mapping)
▸ Scenario: if the key does not exist, compute a value for it.
SIMPLE SYNTACTIC SUGAR - NEW METHODS INSIDE COLLECTIONS
Map interface: forEach method
▸ Definition: forEach(Consumer con)
▸ Scenario: loop through a map
SIMPLE SYNTACTIC SUGAR - NEW METHODS INSIDE COLLECTIONS
Collections interface: removeIf method
▸ Definition: removeIf(Predicate filter)
▸ Scenario: remove an element from the list if specific condition is met
SIMPLE SYNTACTIC SUGAR - NEW METHODS INSIDE COLLECTIONS
Other method
▸ List.sort(Comparator)
▸ Map.putIfAbsent()
▸ Map.replace() / replaceAll()
▸ Map.merge()
▸ Map.compute() / computeIfAbsent() / computeIfPresent()
OUTLINE
▸What will Java 8 give us
▸Behavior parameterization
▸More comprehensive functional interface
▸Lambda expression
▸Method reference
▸Simple syntactic sugar - new methods inside Collections
▸Functional programming - Stream API
▸Intuition
▸Intermediate and terminal operations
▸Properties
▸Alternative to NULL — Optional
▸Changeable Interface — Default methods
▸Asynchronous programming enhancement - Future vs CompletableFuture
▸Other features
▸Dark side of Java 8
▸Conclusion
OUTLINE
▸What will Java 8 give us
▸Behavior parameterization
▸More comprehensive functional interface
▸Lambda expression
▸Method reference
▸Simple syntactic sugar - new methods inside Collections
▸Functional programming - Stream API
▸Intuition
▸Intermediate and terminal operations
▸Properties
▸Alternative to NULL — Optional
▸Changeable Interface — Default methods
▸Asynchronous programming enhancement - Future vs CompletableFuture
▸Other features
▸Dark side of Java 8
▸Conclusion
FUNCTIONAL PROGRAMMING - STREAM API
Stream API
▸ What’s wrong with collections?
▸ Much business logic entails database-like operations such as
grouping a list by category / find the most expensive dish. (Usually
implemented with iterators, could we do it declaratively?)
▸ Big data requires us to utilize multicore processor more frequently.
(Usually implemented with fork/join framework introduced in Java 7.
Could we save some effort? )
FUNCTIONAL PROGRAMMING - STREAM API
Stream API
▸ Def: fancy iterators over collections
▸ Scenario:
FUNCTIONAL PROGRAMMING - STREAM API
FUNCTIONAL PROGRAMMING - STREAM API
FUNCTIONAL PROGRAMMING - STREAM API
How to parallel?
FUNCTIONAL PROGRAMMING - STREAM API
FUNCTIONAL PROGRAMMING - STREAM API
Parallelization realized by Java 7’s fork/join framework underneath
FUNCTIONAL PROGRAMMING - STREAM API
Stream Definition
▸ Stream definition: fancy “internal” iterators over collections
FUNCTIONAL PROGRAMMING - STREAM API
Notice: iterable only once
OUTLINE
▸What will Java 8 give us
▸Behavior parameterization
▸More comprehensive functional interface
▸Lambda expression
▸Method reference
▸Simple syntactic sugar - new methods inside Collections
▸Functional programming - Stream API
▸Intuition
▸Creating, intermediate and terminal operations
▸Properties
▸Alternative to NULL — Optional
▸Changeable Interface — Default methods
▸Asynchronous programming enhancement - Future vs CompletableFuture
▸Other features
▸Dark side of Java 8
▸Conclusion
FUNCTIONAL PROGRAMMING - STREAM API
How to create stream?
▸ From arrays
▸ From collections
▸ Custom generators — Stream.generate() / iterate() method
▸ From other popular APIs
FUNCTIONAL PROGRAMMING - STREAM API
Stream operations
▸ intermediate operations
▸ terminal operations
OUTLINE
▸What will Java 8 give us
▸Behavior parameterization
▸More comprehensive functional interface
▸Lambda expression
▸Method reference
▸Simple syntactic sugar - new methods inside Collections
▸Functional programming - Stream API
▸Intuition
▸Creating, intermediate and terminal operations
▸Use cases
▸Alternative to NULL — Optional
▸Changeable Interface — Default methods
▸Asynchronous programming enhancement - Future vs CompletableFuture
▸Other features
▸Dark side of Java 8
▸Conclusion
FUNCTIONAL PROGRAMMING - STREAM API
Use cases: whenever you want to perform database-like operations
▸ Group/Multi-level group
▸ Filter
▸ Sum/Max/Min/Average/Distinct/Count
▸ Extracting specific properties
▸ ……
OUTLINE
▸What will Java 8 give us
▸Behavior parameterization
▸More comprehensive functional interface
▸Lambda expression
▸Method reference
▸Simple syntactic sugar - new methods inside Collections
▸Functional programming - Stream API
▸Intuition
▸Intermediate and terminal operations
▸Use cases
▸Alternative to NULL — Optional
▸Changeable Interface — Default methods
▸Asynchronous programming enhancement - Future vs CompletableFuture
▸Other features
▸Dark side of Java 8
▸Conclusion
ALTERNATIVE TO NULL — OPTIONAL
Optional definition:
▸ Def: a container may or may not cannot value - just like reference
▸ Benefit 1:
▸ NullPointerException will always be thrown out during runtime
▸ Optional enforces “empty checking” in grammar during compile time
▸ Benefit 2:
▸ Optional interface supports a set of methods makes handling “empty case” easy
ALTERNATIVE TO NULL — OPTIONAL
Optional use case :
▸ http://www.nurkiewicz.com/2013/08/optional-in-java-8-cheat-sheet.html
More use cases:
OUTLINE
▸What will Java 8 give us
▸Behavior parameterization
▸More comprehensive functional interface
▸Lambda expression
▸Method reference
▸Simple syntactic sugar - new methods inside Collections
▸Functional programming - Stream API
▸Intuition
▸Intermediate and terminal operations
▸Properties
▸Alternative to NULL — Optional
▸Changeable Interface — Default methods
▸Asynchronous programming enhancement - Future vs CompletableFuture
▸Other features
▸Dark side of Java 8
▸Conclusion
EVOLVING API — DEFAULT METHODS
Default method
EVOLVING API — DEFAULT METHODS
Default method
▸ Definition: A way to evolve Interface APIs in a compatible way.
▸ As a result, interface could now have methods with implementation
▸ This means “Java supports multiple inheritance”
▸ How does Java solves traditional “Diamond Problem”?
▸ Three resolution rules
▸ http://www.javabrahman.com/java-8/java-8-multiple-inheritance-conflict-
resolution-rules-and-diamond-problem/
OUTLINE
▸What will Java 8 give us
▸Behavior parameterization
▸More comprehensive functional interface
▸Lambda expression
▸Method reference
▸Simple syntactic sugar - new methods inside Collections
▸Functional programming - Stream API
▸Intuition
▸Intermediate and terminal operations
▸Properties
▸Alternative to NULL — Optional
▸Changeable Interface — Default methods
▸Asynchronous programming enhancement - Future vs CompletableFuture
▸Other features
▸Dark side of Java 8
▸Conclusion
COMPOSABLE ASYNCHRONOUS PROGRAMMING — COMPLETABLEFUTURE
Review: Future
▸ Future is used for asynchronous programming
How to combine multiple Future task???
COMPOSABLE ASYNCHRONOUS PROGRAMMING — COMPLETABLEFUTURE
CompletableFuture comes into play
OTHER NEW FEATURES
Other new features
▸ Date and Time API — Handle time zone, separate concerns
▸ JVM Javascript engine — Nashorn
OUTLINE
▸What will Java 8 give us
▸Behavior parameterization
▸More comprehensive functional interface
▸Lambda expression
▸Method reference
▸Simple syntactic sugar - new methods inside Collections
▸Functional programming - Stream API
▸Intuition
▸Intermediate and terminal operations
▸Properties
▸Alternative to NULL — Optional
▸Changeable Interface — Default methods
▸Asynchronous programming enhancement - Future vs CompletableFuture
▸Other features
▸Dark side of Java 8
▸Conclusion
DARKSIDE OF JAVA 8
Dark side of Java 8
▸ Lambda expressions will make debugging log much longer
▸ Not truly functional
▸ Additional reading
▸ http://blog.takipi.com/6-reasons-not-to-switch-to-java-8-just-yet/
▸ Google search “DZone what’s wrong with Java 8”
OUTLINE
▸What will Java 8 give us
▸Behavior parameterization
▸More comprehensive functional interface
▸Lambda expression
▸Method reference
▸Simple syntactic sugar - new methods inside Collections
▸Functional programming - Stream API
▸Intuition
▸Intermediate and terminal operations
▸Properties
▸Alternative to NULL — Optional
▸Changeable Interface — Default methods
▸Asynchronous programming enhancement - Future vs CompletableFuture
▸Other features
▸Dark side of Java 8
▸Conclusion
CONCLUSION
▸ Anonymous class - lambdas
▸ Database-like routines - Stream API
▸ Get to know functional programming
▸ Null pointer exception - Optional
▸ Lots of syntactic sugar in collections method
THANK YOU
Shijie Zhang

More Related Content

What's hot

Apache Camel: The Swiss Army Knife of Open Source Integration
Apache Camel: The Swiss Army Knife of Open Source IntegrationApache Camel: The Swiss Army Knife of Open Source Integration
Apache Camel: The Swiss Army Knife of Open Source Integration
prajods
 
JAX RS and CDI bike the reactive bridge
JAX RS and CDI bike the reactive bridgeJAX RS and CDI bike the reactive bridge
JAX RS and CDI bike the reactive bridge
José Paumard
 
JavaScript for ABAP Programmers - 7/7 Functional Programming
JavaScript for ABAP Programmers - 7/7 Functional ProgrammingJavaScript for ABAP Programmers - 7/7 Functional Programming
JavaScript for ABAP Programmers - 7/7 Functional Programming
Chris Whealy
 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
Wen-Tien Chang
 
Final exam
Final examFinal exam
Final exam
katrinne2012
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
peter_marklund
 
Ruby on Rails 2.1 What's New
Ruby on Rails 2.1 What's NewRuby on Rails 2.1 What's New
Ruby on Rails 2.1 What's New
Libin Pan
 

What's hot (7)

Apache Camel: The Swiss Army Knife of Open Source Integration
Apache Camel: The Swiss Army Knife of Open Source IntegrationApache Camel: The Swiss Army Knife of Open Source Integration
Apache Camel: The Swiss Army Knife of Open Source Integration
 
JAX RS and CDI bike the reactive bridge
JAX RS and CDI bike the reactive bridgeJAX RS and CDI bike the reactive bridge
JAX RS and CDI bike the reactive bridge
 
JavaScript for ABAP Programmers - 7/7 Functional Programming
JavaScript for ABAP Programmers - 7/7 Functional ProgrammingJavaScript for ABAP Programmers - 7/7 Functional Programming
JavaScript for ABAP Programmers - 7/7 Functional Programming
 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
 
Final exam
Final examFinal exam
Final exam
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
 
Ruby on Rails 2.1 What's New
Ruby on Rails 2.1 What's NewRuby on Rails 2.1 What's New
Ruby on Rails 2.1 What's New
 

Viewers also liked

Java8 javatime-api
Java8 javatime-apiJava8 javatime-api
Java8 javatime-api
Jini Lee
 
Java8
Java8Java8
Java8
fbenault
 
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
 
Streams in Java 8
Streams in Java 8Streams in Java 8
Streams in Java 8
Tobias Coetzee
 
Java 8 Date and Time API
Java 8 Date and Time APIJava 8 Date and Time API
Java 8 Date and Time API
Ganesh Samarthyam
 
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
 
Functional Java 8 in everyday life
Functional Java 8 in everyday lifeFunctional Java 8 in everyday life
Functional Java 8 in everyday life
Andrea Iacono
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
Sanjoy Kumar Roy
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
Shahjahan Samoon
 
Java8 training - Class 1
Java8 training  - Class 1Java8 training  - Class 1
Java8 training - Class 1
Marut Singh
 
Java8 training - class 3
Java8 training - class 3Java8 training - class 3
Java8 training - class 3
Marut Singh
 
Java8 training - class 2
Java8 training - class 2Java8 training - class 2
Java8 training - class 2
Marut Singh
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
Hoang Nguyen
 
Building Applications with a Graph Database
Building Applications with a Graph DatabaseBuilding Applications with a Graph Database
Building Applications with a Graph Database
Tobias Lindaaker
 
What is concurrency
What is concurrencyWhat is concurrency
What is concurrency
lodhran-hayat
 
Jumping-with-java8
Jumping-with-java8Jumping-with-java8
Jumping-with-java8
Dhaval Dalal
 
Apache camel
Apache camelApache camel
Apache camel
Marut Singh
 
Java Hands-On Workshop
Java Hands-On WorkshopJava Hands-On Workshop
Java Hands-On Workshop
Arpit Poladia
 
Concurrency & Parallel Programming
Concurrency & Parallel ProgrammingConcurrency & Parallel Programming
Concurrency & Parallel Programming
Ramazan AYYILDIZ
 
Java day2016 "Reinventing design patterns with java 8"
Java day2016 "Reinventing design patterns with java 8"Java day2016 "Reinventing design patterns with java 8"
Java day2016 "Reinventing design patterns with java 8"
Alexander Pashynskiy
 

Viewers also liked (20)

Java8 javatime-api
Java8 javatime-apiJava8 javatime-api
Java8 javatime-api
 
Java8
Java8Java8
Java8
 
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
 
Streams in Java 8
Streams in Java 8Streams in Java 8
Streams in Java 8
 
Java 8 Date and Time API
Java 8 Date and Time APIJava 8 Date and Time API
Java 8 Date and Time API
 
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
 
Functional Java 8 in everyday life
Functional Java 8 in everyday lifeFunctional Java 8 in everyday life
Functional Java 8 in everyday life
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
 
Java8 training - Class 1
Java8 training  - Class 1Java8 training  - Class 1
Java8 training - Class 1
 
Java8 training - class 3
Java8 training - class 3Java8 training - class 3
Java8 training - class 3
 
Java8 training - class 2
Java8 training - class 2Java8 training - class 2
Java8 training - class 2
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
 
Building Applications with a Graph Database
Building Applications with a Graph DatabaseBuilding Applications with a Graph Database
Building Applications with a Graph Database
 
What is concurrency
What is concurrencyWhat is concurrency
What is concurrency
 
Jumping-with-java8
Jumping-with-java8Jumping-with-java8
Jumping-with-java8
 
Apache camel
Apache camelApache camel
Apache camel
 
Java Hands-On Workshop
Java Hands-On WorkshopJava Hands-On Workshop
Java Hands-On Workshop
 
Concurrency & Parallel Programming
Concurrency & Parallel ProgrammingConcurrency & Parallel Programming
Concurrency & Parallel Programming
 
Java day2016 "Reinventing design patterns with java 8"
Java day2016 "Reinventing design patterns with java 8"Java day2016 "Reinventing design patterns with java 8"
Java day2016 "Reinventing design patterns with java 8"
 

Similar to Java8

Going Serverless on AWS with Golang and SAM
Going Serverless on AWS with Golang and SAMGoing Serverless on AWS with Golang and SAM
Going Serverless on AWS with Golang and SAM
George Tourkas
 
GraphQL And Relay Modern
GraphQL And Relay ModernGraphQL And Relay Modern
GraphQL And Relay Modern
Brad Pillow
 
GraphQL and Relay Modern
GraphQL and Relay ModernGraphQL and Relay Modern
GraphQL and Relay Modern
Carmel JavaScript Roundabout
 
GraphQL And Relay Modern
GraphQL And Relay ModernGraphQL And Relay Modern
GraphQL And Relay Modern
Brad Pillow
 
The GrapQL ecosystem
The GrapQL ecosystemThe GrapQL ecosystem
The GrapQL ecosystem
OlegsGabrusjonoks
 
Rspamd testing
Rspamd testingRspamd testing
Rspamd testing
Vsevolod Stakhov
 
The Best Feature of Go – A 5 Year Retrospective
The Best Feature of Go – A 5 Year RetrospectiveThe Best Feature of Go – A 5 Year Retrospective
The Best Feature of Go – A 5 Year Retrospective
Tahir Hashmi
 
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
 
Java 8 - A step closer to Parallelism
Java 8 - A step closer to ParallelismJava 8 - A step closer to Parallelism
Java 8 - A step closer to Parallelism
jbugkorea
 
GraphQL IndyJS April 2016
GraphQL IndyJS April 2016GraphQL IndyJS April 2016
GraphQL IndyJS April 2016
Brad Pillow
 
Colloquium Report
Colloquium ReportColloquium Report
Colloquium Report
Mohammad Faizan
 
Reactive Programming - ReactFoo 2020 - Aziz Khambati
Reactive Programming - ReactFoo 2020 - Aziz KhambatiReactive Programming - ReactFoo 2020 - Aziz Khambati
Reactive Programming - ReactFoo 2020 - Aziz Khambati
Aziz Khambati
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8
Knoldus Inc.
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
Nicola Pedot
 
rx-java-presentation
rx-java-presentationrx-java-presentation
rx-java-presentation
Mateusz Bukowicz
 
System webpack-jspm
System webpack-jspmSystem webpack-jspm
System webpack-jspm
Jesse Warden
 
Cascading on starfish
Cascading on starfishCascading on starfish
Cascading on starfish
Fei Dong
 
ShadowReader - Serverless load tests for replaying production traffic
ShadowReader - Serverless load tests for replaying production trafficShadowReader - Serverless load tests for replaying production traffic
ShadowReader - Serverless load tests for replaying production traffic
Yuki Sawa
 
Spark core
Spark coreSpark core
Spark core
Freeman Zhang
 
Confitura 2018 — Apache Beam — Promyk Nadziei Data Engineera
Confitura 2018 — Apache Beam — Promyk Nadziei Data EngineeraConfitura 2018 — Apache Beam — Promyk Nadziei Data Engineera
Confitura 2018 — Apache Beam — Promyk Nadziei Data Engineera
Piotr Wikiel
 

Similar to Java8 (20)

Going Serverless on AWS with Golang and SAM
Going Serverless on AWS with Golang and SAMGoing Serverless on AWS with Golang and SAM
Going Serverless on AWS with Golang and SAM
 
GraphQL And Relay Modern
GraphQL And Relay ModernGraphQL And Relay Modern
GraphQL And Relay Modern
 
GraphQL and Relay Modern
GraphQL and Relay ModernGraphQL and Relay Modern
GraphQL and Relay Modern
 
GraphQL And Relay Modern
GraphQL And Relay ModernGraphQL And Relay Modern
GraphQL And Relay Modern
 
The GrapQL ecosystem
The GrapQL ecosystemThe GrapQL ecosystem
The GrapQL ecosystem
 
Rspamd testing
Rspamd testingRspamd testing
Rspamd testing
 
The Best Feature of Go – A 5 Year Retrospective
The Best Feature of Go – A 5 Year RetrospectiveThe Best Feature of Go – A 5 Year Retrospective
The Best Feature of Go – A 5 Year Retrospective
 
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
 
Java 8 - A step closer to Parallelism
Java 8 - A step closer to ParallelismJava 8 - A step closer to Parallelism
Java 8 - A step closer to Parallelism
 
GraphQL IndyJS April 2016
GraphQL IndyJS April 2016GraphQL IndyJS April 2016
GraphQL IndyJS April 2016
 
Colloquium Report
Colloquium ReportColloquium Report
Colloquium Report
 
Reactive Programming - ReactFoo 2020 - Aziz Khambati
Reactive Programming - ReactFoo 2020 - Aziz KhambatiReactive Programming - ReactFoo 2020 - Aziz Khambati
Reactive Programming - ReactFoo 2020 - Aziz Khambati
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
 
rx-java-presentation
rx-java-presentationrx-java-presentation
rx-java-presentation
 
System webpack-jspm
System webpack-jspmSystem webpack-jspm
System webpack-jspm
 
Cascading on starfish
Cascading on starfishCascading on starfish
Cascading on starfish
 
ShadowReader - Serverless load tests for replaying production traffic
ShadowReader - Serverless load tests for replaying production trafficShadowReader - Serverless load tests for replaying production traffic
ShadowReader - Serverless load tests for replaying production traffic
 
Spark core
Spark coreSpark core
Spark core
 
Confitura 2018 — Apache Beam — Promyk Nadziei Data Engineera
Confitura 2018 — Apache Beam — Promyk Nadziei Data EngineeraConfitura 2018 — Apache Beam — Promyk Nadziei Data Engineera
Confitura 2018 — Apache Beam — Promyk Nadziei Data Engineera
 

Recently uploaded

The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
kalichargn70th171
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
kgyxske
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
Orca: Nocode Graphical Editor for Container Orchestration
Orca: Nocode Graphical Editor for Container OrchestrationOrca: Nocode Graphical Editor for Container Orchestration
Orca: Nocode Graphical Editor for Container Orchestration
Pedro J. Molina
 
42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert
vaishalijagtap12
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
gapen1
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
widenerjobeyrl638
 
Kubernetes at Scale: Going Multi-Cluster with Istio
Kubernetes at Scale:  Going Multi-Cluster  with IstioKubernetes at Scale:  Going Multi-Cluster  with Istio
Kubernetes at Scale: Going Multi-Cluster with Istio
Severalnines
 
What’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete RoadmapWhat’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete Roadmap
Envertis Software Solutions
 
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
Luigi Fugaro
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Paul Brebner
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
Yara Milbes
 
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and MoreManyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
narinav14
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
Maitrey Patel
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdfThe Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
kalichargn70th171
 

Recently uploaded (20)

The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
Orca: Nocode Graphical Editor for Container Orchestration
Orca: Nocode Graphical Editor for Container OrchestrationOrca: Nocode Graphical Editor for Container Orchestration
Orca: Nocode Graphical Editor for Container Orchestration
 
42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
 
Kubernetes at Scale: Going Multi-Cluster with Istio
Kubernetes at Scale:  Going Multi-Cluster  with IstioKubernetes at Scale:  Going Multi-Cluster  with Istio
Kubernetes at Scale: Going Multi-Cluster with Istio
 
What’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete RoadmapWhat’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete Roadmap
 
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
 
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and MoreManyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdfThe Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
 

Java8

  • 1. INTRO TO JAVA 8 SHIJIE ZHANG
  • 2. OUTLINE ▸What will Java 8 give us ▸Behavior parameterization ▸More comprehensive functional interface ▸Lambda expression ▸Method reference ▸Simple syntactic sugar - new methods inside Collections ▸Functional programming - Stream API ▸Intuition ▸Intermediate and terminal operations ▸Properties ▸Alternative to NULL — Optional ▸Changeable Interface — Default methods ▸Asynchronous programming enhancement - Future vs CompletableFuture ▸Other features ▸Dark side of Java 8 ▸Conclusion
  • 3. WHAT WILL JAVA 8 BRING US CLIMATE IS CHANGING ▸ Java was in dominant positions due to its simplicity, portability, safety and free to use. ▸ JVM-based dynamic language comes up, known for their simplicity and portability. (Groovy, Clojure, Scala) ▸ Big data is on the rise. Programmers need to deal with large collections. ▸ Multicore processor is becoming more and more popular. Programmers need to an easier way to do parallel programming. ▸ Java is kind of verbose.
  • 4. WHAT WILL JAVA 8 BRING US
  • 5. OUTLINE ▸What will Java 8 give us ▸Behavior parameterization ▸More comprehensive functional interface ▸Lambda expression ▸Method reference ▸Simple syntactic sugar - new methods inside Collections ▸Functional programming - Stream API ▸Intuition ▸Intermediate and terminal operations ▸Properties ▸Alternative to NULL — Optional ▸Changeable Interface — Default methods ▸Asynchronous programming enhancement - Future vs CompletableFuture ▸Other features ▸Dark side of Java 8 ▸Conclusion
  • 6. OUTLINE ▸What will Java 8 give us ▸Behavior parameterization ▸More comprehensive functional interface ▸Lambda expression ▸Method reference ▸Simple syntactic sugar - new methods inside Collections ▸Functional programming - Stream API ▸Intuition ▸Intermediate and terminal operations ▸Properties ▸Alternative to NULL — Optional ▸Changeable Interface — Default methods ▸Asynchronous programming enhancement - Future vs CompletableFuture ▸Other features ▸Dark side of Java 8 ▸Conclusion
  • 7. BEHAVIOR PARAMETERIZATION - LAMBDAS More comprehensive functional interface ▸ Comparator is an interface. More exactly, a functional interface.
  • 8. BEHAVIOR PARAMETERIZATION - LAMBDAS More comprehensive functional interface ▸ Functional interface: an interface has exactly one abstract method ▸ Several functional interface exists before Java 8 ▸ Functional interface enables behavior parameterization
  • 10. BEHAVIOR PARAMETERIZATION - LAMBDAS Where to use functional interface ▸ Anywhere an object could be used ▸ method arguments/parameters/return types ▸ inside collections ▸ Variables ▸ …….
  • 11. BEHAVIOR PARAMETERIZATION - LAMBDAS In the past, use anonymous class as instance for functional interface Now, use lambda expression/method reference as instance for functional interface ▸ Think about Comparator — create an anonymous class ▸ All anonymous class could be replaced with lambda/method reference ▸ Anonymous class ~ lambda expression ~ method reference ▸ lambda expressions ▸ method reference
  • 12. OUTLINE ▸What will Java 8 give us ▸Behavior parameterization ▸More comprehensive functional interface ▸Lambda expression ▸Method reference ▸Simple syntactic sugar - new methods inside Collections ▸Functional programming - Stream API ▸Intuition ▸Intermediate and terminal operations ▸Properties ▸Alternative to NULL — Optional ▸Changeable Interface — Default methods ▸Asynchronous programming enhancement - Future vs CompletableFuture ▸Other features ▸Dark side of Java 8 ▸Conclusion
  • 13. BEHAVIOR PARAMETERIZATION - LAMBDAS Lambdas definition ▸ Definition ▸ Examples: 1. ( ) -> { } 2. ( ) -> “Raoul” 3. ( ) -> { return “Mario”;} 4. ( Integer i ) -> return “Alan” + i; 5. ( String s ) -> { “Iron Man”; }
  • 14. BEHAVIOR PARAMETERIZATION - LAMBDAS Lambdas definition ▸ Definition ▸ Examples: 1. ( ) -> { } 2. ( ) -> “Raoul” 3. ( ) -> { return “Mario”;} 4. ( Integer i ) -> return “Alan” + i; 5. ( String s ) -> { “Iron Man”; }
  • 15. BEHAVIOR PARAMETERIZATION - LAMBDAS Lambda use cases - whenever you use anonymous class
  • 17. BEHAVIOR PARAMETERIZATION - LAMBDAS Type reference Restriction on local variables ▸ Definition
  • 18. OUTLINE ▸What will Java 8 give us ▸Behavior parameterization ▸More comprehensive functional interface ▸Lambda expression ▸Method reference ▸Simple syntactic sugar - new methods inside Collections ▸Functional programming - Stream API ▸Intuition ▸Intermediate and terminal operations ▸Properties ▸Alternative to NULL — Optional ▸Changeable Interface — Default methods ▸Asynchronous programming enhancement - Future vs CompletableFuture ▸Other features ▸Dark side of Java 8 ▸Conclusion
  • 19. BEHAVIOR PARAMETERIZATION - LAMBDAS Method reference definition ▸ Definition: syntactic sugar for lambda expressions
  • 20. BEHAVIOR PARAMETERIZATION - LAMBDAS Rules for converting lambda to method reference ▸ A method reference to a static method ▸ A method reference to an instance method of an arbitrary type ▸ A method reference to an instance method of an existing object
  • 21. OUTLINE ▸What will Java 8 give us ▸Behavior parameterization ▸More comprehensive functional interface ▸Lambda expression ▸Method reference ▸Simple syntactic sugar - new methods inside Collections ▸Functional programming - Stream API ▸Intuition ▸Intermediate and terminal operations ▸Properties ▸Alternative to NULL — Optional ▸Changeable Interface — Default methods ▸Asynchronous programming enhancement - Future vs CompletableFuture ▸Other features ▸Dark side of Java 8 ▸Conclusion
  • 22. SIMPLE SYNTACTIC SUGAR - NEW METHODS INSIDE COLLECTIONS Map interface: getOrDefault method ▸ Definition: getOrDefault(K key, V defaultValue) ▸ Scenario: get a value (may not exist) from a map, do some calculation and put it back
  • 23. SIMPLE SYNTACTIC SUGAR - NEW METHODS INSIDE COLLECTIONS Map interface: computeIfAbsent method ▸ Definition: computeIfAbsent(K key, Function mapping) ▸ Scenario: if the key does not exist, compute a value for it.
  • 24. SIMPLE SYNTACTIC SUGAR - NEW METHODS INSIDE COLLECTIONS Map interface: forEach method ▸ Definition: forEach(Consumer con) ▸ Scenario: loop through a map
  • 25. SIMPLE SYNTACTIC SUGAR - NEW METHODS INSIDE COLLECTIONS Collections interface: removeIf method ▸ Definition: removeIf(Predicate filter) ▸ Scenario: remove an element from the list if specific condition is met
  • 26. SIMPLE SYNTACTIC SUGAR - NEW METHODS INSIDE COLLECTIONS Other method ▸ List.sort(Comparator) ▸ Map.putIfAbsent() ▸ Map.replace() / replaceAll() ▸ Map.merge() ▸ Map.compute() / computeIfAbsent() / computeIfPresent()
  • 27. OUTLINE ▸What will Java 8 give us ▸Behavior parameterization ▸More comprehensive functional interface ▸Lambda expression ▸Method reference ▸Simple syntactic sugar - new methods inside Collections ▸Functional programming - Stream API ▸Intuition ▸Intermediate and terminal operations ▸Properties ▸Alternative to NULL — Optional ▸Changeable Interface — Default methods ▸Asynchronous programming enhancement - Future vs CompletableFuture ▸Other features ▸Dark side of Java 8 ▸Conclusion
  • 28. OUTLINE ▸What will Java 8 give us ▸Behavior parameterization ▸More comprehensive functional interface ▸Lambda expression ▸Method reference ▸Simple syntactic sugar - new methods inside Collections ▸Functional programming - Stream API ▸Intuition ▸Intermediate and terminal operations ▸Properties ▸Alternative to NULL — Optional ▸Changeable Interface — Default methods ▸Asynchronous programming enhancement - Future vs CompletableFuture ▸Other features ▸Dark side of Java 8 ▸Conclusion
  • 29. FUNCTIONAL PROGRAMMING - STREAM API Stream API ▸ What’s wrong with collections? ▸ Much business logic entails database-like operations such as grouping a list by category / find the most expensive dish. (Usually implemented with iterators, could we do it declaratively?) ▸ Big data requires us to utilize multicore processor more frequently. (Usually implemented with fork/join framework introduced in Java 7. Could we save some effort? )
  • 30. FUNCTIONAL PROGRAMMING - STREAM API Stream API ▸ Def: fancy iterators over collections ▸ Scenario:
  • 33. FUNCTIONAL PROGRAMMING - STREAM API How to parallel?
  • 35. FUNCTIONAL PROGRAMMING - STREAM API Parallelization realized by Java 7’s fork/join framework underneath
  • 36. FUNCTIONAL PROGRAMMING - STREAM API Stream Definition ▸ Stream definition: fancy “internal” iterators over collections
  • 37. FUNCTIONAL PROGRAMMING - STREAM API Notice: iterable only once
  • 38. OUTLINE ▸What will Java 8 give us ▸Behavior parameterization ▸More comprehensive functional interface ▸Lambda expression ▸Method reference ▸Simple syntactic sugar - new methods inside Collections ▸Functional programming - Stream API ▸Intuition ▸Creating, intermediate and terminal operations ▸Properties ▸Alternative to NULL — Optional ▸Changeable Interface — Default methods ▸Asynchronous programming enhancement - Future vs CompletableFuture ▸Other features ▸Dark side of Java 8 ▸Conclusion
  • 39. FUNCTIONAL PROGRAMMING - STREAM API How to create stream? ▸ From arrays ▸ From collections ▸ Custom generators — Stream.generate() / iterate() method ▸ From other popular APIs
  • 40. FUNCTIONAL PROGRAMMING - STREAM API Stream operations ▸ intermediate operations ▸ terminal operations
  • 41. OUTLINE ▸What will Java 8 give us ▸Behavior parameterization ▸More comprehensive functional interface ▸Lambda expression ▸Method reference ▸Simple syntactic sugar - new methods inside Collections ▸Functional programming - Stream API ▸Intuition ▸Creating, intermediate and terminal operations ▸Use cases ▸Alternative to NULL — Optional ▸Changeable Interface — Default methods ▸Asynchronous programming enhancement - Future vs CompletableFuture ▸Other features ▸Dark side of Java 8 ▸Conclusion
  • 42. FUNCTIONAL PROGRAMMING - STREAM API Use cases: whenever you want to perform database-like operations ▸ Group/Multi-level group ▸ Filter ▸ Sum/Max/Min/Average/Distinct/Count ▸ Extracting specific properties ▸ ……
  • 43. OUTLINE ▸What will Java 8 give us ▸Behavior parameterization ▸More comprehensive functional interface ▸Lambda expression ▸Method reference ▸Simple syntactic sugar - new methods inside Collections ▸Functional programming - Stream API ▸Intuition ▸Intermediate and terminal operations ▸Use cases ▸Alternative to NULL — Optional ▸Changeable Interface — Default methods ▸Asynchronous programming enhancement - Future vs CompletableFuture ▸Other features ▸Dark side of Java 8 ▸Conclusion
  • 44. ALTERNATIVE TO NULL — OPTIONAL Optional definition: ▸ Def: a container may or may not cannot value - just like reference ▸ Benefit 1: ▸ NullPointerException will always be thrown out during runtime ▸ Optional enforces “empty checking” in grammar during compile time ▸ Benefit 2: ▸ Optional interface supports a set of methods makes handling “empty case” easy
  • 45. ALTERNATIVE TO NULL — OPTIONAL Optional use case : ▸ http://www.nurkiewicz.com/2013/08/optional-in-java-8-cheat-sheet.html More use cases:
  • 46. OUTLINE ▸What will Java 8 give us ▸Behavior parameterization ▸More comprehensive functional interface ▸Lambda expression ▸Method reference ▸Simple syntactic sugar - new methods inside Collections ▸Functional programming - Stream API ▸Intuition ▸Intermediate and terminal operations ▸Properties ▸Alternative to NULL — Optional ▸Changeable Interface — Default methods ▸Asynchronous programming enhancement - Future vs CompletableFuture ▸Other features ▸Dark side of Java 8 ▸Conclusion
  • 47. EVOLVING API — DEFAULT METHODS Default method
  • 48. EVOLVING API — DEFAULT METHODS Default method ▸ Definition: A way to evolve Interface APIs in a compatible way. ▸ As a result, interface could now have methods with implementation ▸ This means “Java supports multiple inheritance” ▸ How does Java solves traditional “Diamond Problem”? ▸ Three resolution rules ▸ http://www.javabrahman.com/java-8/java-8-multiple-inheritance-conflict- resolution-rules-and-diamond-problem/
  • 49. OUTLINE ▸What will Java 8 give us ▸Behavior parameterization ▸More comprehensive functional interface ▸Lambda expression ▸Method reference ▸Simple syntactic sugar - new methods inside Collections ▸Functional programming - Stream API ▸Intuition ▸Intermediate and terminal operations ▸Properties ▸Alternative to NULL — Optional ▸Changeable Interface — Default methods ▸Asynchronous programming enhancement - Future vs CompletableFuture ▸Other features ▸Dark side of Java 8 ▸Conclusion
  • 50. COMPOSABLE ASYNCHRONOUS PROGRAMMING — COMPLETABLEFUTURE Review: Future ▸ Future is used for asynchronous programming How to combine multiple Future task???
  • 51. COMPOSABLE ASYNCHRONOUS PROGRAMMING — COMPLETABLEFUTURE CompletableFuture comes into play
  • 52. OTHER NEW FEATURES Other new features ▸ Date and Time API — Handle time zone, separate concerns ▸ JVM Javascript engine — Nashorn
  • 53. OUTLINE ▸What will Java 8 give us ▸Behavior parameterization ▸More comprehensive functional interface ▸Lambda expression ▸Method reference ▸Simple syntactic sugar - new methods inside Collections ▸Functional programming - Stream API ▸Intuition ▸Intermediate and terminal operations ▸Properties ▸Alternative to NULL — Optional ▸Changeable Interface — Default methods ▸Asynchronous programming enhancement - Future vs CompletableFuture ▸Other features ▸Dark side of Java 8 ▸Conclusion
  • 54. DARKSIDE OF JAVA 8 Dark side of Java 8 ▸ Lambda expressions will make debugging log much longer ▸ Not truly functional ▸ Additional reading ▸ http://blog.takipi.com/6-reasons-not-to-switch-to-java-8-just-yet/ ▸ Google search “DZone what’s wrong with Java 8”
  • 55. OUTLINE ▸What will Java 8 give us ▸Behavior parameterization ▸More comprehensive functional interface ▸Lambda expression ▸Method reference ▸Simple syntactic sugar - new methods inside Collections ▸Functional programming - Stream API ▸Intuition ▸Intermediate and terminal operations ▸Properties ▸Alternative to NULL — Optional ▸Changeable Interface — Default methods ▸Asynchronous programming enhancement - Future vs CompletableFuture ▸Other features ▸Dark side of Java 8 ▸Conclusion
  • 56. CONCLUSION ▸ Anonymous class - lambdas ▸ Database-like routines - Stream API ▸ Get to know functional programming ▸ Null pointer exception - Optional ▸ Lots of syntactic sugar in collections method