SlideShare una empresa de Scribd logo
1 de 57
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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 Integrationprajods
 
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 bridgeJosé 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 ProgrammingChris Whealy
 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and RailsWen-Tien Chang
 
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 Coursepeter_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 NewLibin Pan
 

La actualidad más candente (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
 

Destacado

Java8 javatime-api
Java8 javatime-apiJava8 javatime-api
Java8 javatime-apiJini Lee
 
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 InterfacesGanesh 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 OverviewEclipse Day India
 
Functional Java 8 in everyday life
Functional Java 8 in everyday lifeFunctional Java 8 in everyday life
Functional Java 8 in everyday lifeAndrea Iacono
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streamsShahjahan Samoon
 
Java8 training - Class 1
Java8 training  - Class 1Java8 training  - Class 1
Java8 training - Class 1Marut Singh
 
Java8 training - class 3
Java8 training - class 3Java8 training - class 3
Java8 training - class 3Marut Singh
 
Java8 training - class 2
Java8 training - class 2Java8 training - class 2
Java8 training - class 2Marut Singh
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with javaHoang Nguyen
 
Building Applications with a Graph Database
Building Applications with a Graph DatabaseBuilding Applications with a Graph Database
Building Applications with a Graph DatabaseTobias Lindaaker
 
Jumping-with-java8
Jumping-with-java8Jumping-with-java8
Jumping-with-java8Dhaval Dalal
 
Java Hands-On Workshop
Java Hands-On WorkshopJava Hands-On Workshop
Java Hands-On WorkshopArpit Poladia
 
Concurrency & Parallel Programming
Concurrency & Parallel ProgrammingConcurrency & Parallel Programming
Concurrency & Parallel ProgrammingRamazan 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
 

Destacado (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 a 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 SAMGeorge Tourkas
 
GraphQL And Relay Modern
GraphQL And Relay ModernGraphQL And Relay Modern
GraphQL And Relay ModernBrad Pillow
 
GraphQL And Relay Modern
GraphQL And Relay ModernGraphQL And Relay Modern
GraphQL And Relay ModernBrad Pillow
 
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 RetrospectiveTahir 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 StreamsEmiel 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 Parallelismjbugkorea
 
GraphQL IndyJS April 2016
GraphQL IndyJS April 2016GraphQL IndyJS April 2016
GraphQL IndyJS April 2016Brad Pillow
 
Reactive Programming - ReactFoo 2020 - Aziz Khambati
Reactive Programming - ReactFoo 2020 - Aziz KhambatiReactive Programming - ReactFoo 2020 - Aziz Khambati
Reactive Programming - ReactFoo 2020 - Aziz KhambatiAziz Khambati
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8Knoldus Inc.
 
System webpack-jspm
System webpack-jspmSystem webpack-jspm
System webpack-jspmJesse Warden
 
Cascading on starfish
Cascading on starfishCascading on starfish
Cascading on starfishFei 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 trafficYuki Sawa
 
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 EngineeraPiotr Wikiel
 

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

Último

Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 

Último (20)

Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 

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