SlideShare une entreprise Scribd logo
1  sur  23
© Copyright Azul Systems 2017 1
© Copyright Azul Systems 2017
© Copyright Azul Systems 2015
@speakjava
What’s New For
Developers In JDK 9
Simon Ritter
Deputy CTO, Azul Systems
2
© Copyright Azul Systems 2017
Convenience Factory Methods
For Collections (JEP 269)
© Copyright Azul Systems 2017
Factory Methods For Collections (JEP 269)
 The problem:
– Creating a small unmodifiable collection is verbose
4
Set<String> set = new HashSet<>();
set.add("a");
set.add("b");
set.add("c");
set = Collections.unmodifiableSet(set);
© Copyright Azul Systems 2017
Factory Methods For Collections (JEP 269)
 Static methods added to List, Set and Map interfaces
– Create compact, immutable instances
– 0 to 10 element overloaded versions
– Varargs version for arbitary number of elements
5
Set<String> set = Set.of("a", "b", "c");
List<String> list = List.of("a", "b", "c");
Map<String, String> map = Map.of(“k1”, “v1”, “k2”, “v2”);
Map<String, String> map = Map.ofEntries(
entry(“k1”, “v1”), entry(“k2”, “v2”));
© Copyright Azul Systems 2017
New APIs For Streams
© Copyright Azul Systems 2017
dropWhile/takeWhile
 Like skip() and limit(), but taking a Predicate
– takeWhile can convert an infinite stream to a finite one
– Be careful of unordered streams missing values
7
list.stream()
.dropWhile(s -> s.charAt(0) < ‘e')
.forEach(System.out::println);
List<String> list = List.of("alpha", "bravo", "charlie",
"delta", "echo", "foxtrot");
list.stream()
.takeWhile(s -> s.length() == 5)
.forEach(System.out::println);
alpha
bravo
delta
echo
foxtrot
© Copyright Azul Systems 2017
Improved Iteration
 iterate(seed, hasNext, next)
– Can be used like the classic for loop
8
Initial
value
Predicate UnaryOperator
IntStream.iterate(0, i -> i < 10, i -> ++i)
.forEach(System.out::println);
IntStream.iterate(0, i -> i < 10, i -> i++)
.forEach(System.out::println);
Infinite stream
© Copyright Azul Systems 2017
New APIs For Optional
© Copyright Azul Systems 2017
New Methods
 ifPresentOrElse(Consumer action, Runnable emptyAction)
– If a value is present call accept() on action with the value
– Otherwise, run the emptyAction
 Not in a separate thread
 or(Supplier<? extends Optional<? extends T>> supplier)
– Return the Optional if there is a value
– Otherwise, return a new Optional created by the Supplier
 stream()
– Returns a stream of zero or one element
10
© Copyright Azul Systems 2017
Langauge Changes (JEP 213)
© Copyright Azul Systems 2017
Milling Project Coin
 Single underscore is now a reserved word
– No longer usable as an identifier
– Two or more underscores still works
 Allow @SafeVarargs on private instance methods
– In addition to constructors, final and static methods
12
© Copyright Azul Systems 2017
Milling Project Coin
 Private methods are now permitted in interfaces
– Separate common code for default and static methods
13
public interface MyInterface {
default int getX() {
return getNum() * 2;
};
static int getY() {
return getNum() * 4;
}
private static int getNum() {
return 12;
}
}
© Copyright Azul Systems 2017
Milling Project Coin
 Effectively final variables in try-with-resources
14
BufferedReader reader =
new BufferedReader(new FileReader("/tmp/foo.txt"));
try (BufferedReader myReader = reader) {
myReader.lines()
.forEach(System.out::println);
}
JDK 8
try (reader) {
reader.lines()
.forEach(System.out::println);
}
© Copyright Azul Systems 2017
Milling Project Coin
 Diamond operator with anonymous classes
– Type inference can infer a non-denotable type
– If the type inferred can be denotable you can use <>
15
public abstract class Processor<T> {
abstract void use(T value);
}
Processor<String> processor = new Processor<>() {
@Override
void use(String value) {
// Some stuff
}
};
© Copyright Azul Systems 2017
More Concurrency:
Reactive Streams (JEP 266)
© Copyright Azul Systems 2017
The Problem
17
Publisher Subscriber
Process
Process
Process
Process
BLOCK
© Copyright Azul Systems 2017
Reactive Streams: Flow API
 Set of interfaces
 Publisher
– Producer of items to be received by Subscribers
 Subscriber
– Receiver of messages
 Processor
– Both a Publisher and Subscriber (chaining)
 Subscription
– Message control linking a Publisher and Subscriber
18
© Copyright Azul Systems 2017
Reactive Streams: Flow API
 Publisher
– subscribe(Subscriber)
 Subscriber
– OnSubscribe(Subscription)
– onNext(T item)
– onComplete() / onError(Throwable)
 Subscription
– request(long)
– cancel()
19
© Copyright Azul Systems 2017
Solution
20
Publisher Subscriber
Subscription
request(4)
subscribe
onSubscribe
onItem
onItem
onItem
onItem
request(2)
© Copyright Azul Systems 2017
Conclusions
 JDK 9 adds some useful features
– Minor language changes
– Small updates to streams API and Optional
– Factory methods for collections
– Reactive stream API is probably biggest new feature
 More not covered here
– CompletableFuture additions
– Stack walking API
– Process API enhancements
21
© Copyright Azul Systems 2017
Quick Poll
 How excited are you about the release of JDK 9?
a. Can't wait to get using all those great new features
b. Looks interesting, but I’m pretty happy with JDK 8
c. The module system looks scarey
d. When's JDK 10 being released?
22
© Copyright Azul Systems 2017
© Copyright Azul Systems 2015
@speakjava
Thank You!
zulu.org
Free certified OpenJDK binaries
Simon Ritter
Deputy CTO, Azul Systems
23

Contenu connexe

Tendances

Getting the Most From Modern Java
Getting the Most From Modern JavaGetting the Most From Modern Java
Getting the Most From Modern JavaSimon Ritter
 
Brief introduction on Hadoop,Dremel, Pig, FlumeJava and Cassandra
Brief introduction on Hadoop,Dremel, Pig, FlumeJava and CassandraBrief introduction on Hadoop,Dremel, Pig, FlumeJava and Cassandra
Brief introduction on Hadoop,Dremel, Pig, FlumeJava and CassandraSomnath Mazumdar
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJavaJobaer Chowdhury
 
Proxy Deep Dive JUG Saxony Day 2015-10-02
Proxy Deep Dive JUG Saxony Day 2015-10-02Proxy Deep Dive JUG Saxony Day 2015-10-02
Proxy Deep Dive JUG Saxony Day 2015-10-02Sven Ruppert
 
Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3Simon Ritter
 
Unit testing of spark applications
Unit testing of spark applicationsUnit testing of spark applications
Unit testing of spark applicationsKnoldus Inc.
 
Chapel-on-X: Exploring Tasking Runtimes for PGAS Languages
Chapel-on-X: Exploring Tasking Runtimes for PGAS LanguagesChapel-on-X: Exploring Tasking Runtimes for PGAS Languages
Chapel-on-X: Exploring Tasking Runtimes for PGAS LanguagesAkihiro Hayashi
 
Spark Summit EU talk by Nimbus Goehausen
Spark Summit EU talk by Nimbus GoehausenSpark Summit EU talk by Nimbus Goehausen
Spark Summit EU talk by Nimbus GoehausenSpark Summit
 
JDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
JDK8 Lambdas and Streams: Changing The Way You Think When Developing JavaJDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
JDK8 Lambdas and Streams: Changing The Way You Think When Developing JavaSimon Ritter
 
Kotlin Receiver Types 介紹
Kotlin Receiver Types 介紹Kotlin Receiver Types 介紹
Kotlin Receiver Types 介紹Kros Huang
 
Rxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJavaRxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJavaKros Huang
 
Lambdas : Beyond The Basics
Lambdas : Beyond The BasicsLambdas : Beyond The Basics
Lambdas : Beyond The BasicsSimon Ritter
 
Introduction to ScalaZ
Introduction to ScalaZIntroduction to ScalaZ
Introduction to ScalaZKnoldus Inc.
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for AndroidTomáš Kypta
 
Stream processing from single node to a cluster
Stream processing from single node to a clusterStream processing from single node to a cluster
Stream processing from single node to a clusterGal Marder
 
How to Think in RxJava Before Reacting
How to Think in RxJava Before ReactingHow to Think in RxJava Before Reacting
How to Think in RxJava Before ReactingIndicThreads
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaRick Warren
 

Tendances (20)

Java after 8
Java after 8Java after 8
Java after 8
 
Getting the Most From Modern Java
Getting the Most From Modern JavaGetting the Most From Modern Java
Getting the Most From Modern Java
 
Brief introduction on Hadoop,Dremel, Pig, FlumeJava and Cassandra
Brief introduction on Hadoop,Dremel, Pig, FlumeJava and CassandraBrief introduction on Hadoop,Dremel, Pig, FlumeJava and Cassandra
Brief introduction on Hadoop,Dremel, Pig, FlumeJava and Cassandra
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJava
 
Proxy Deep Dive JUG Saxony Day 2015-10-02
Proxy Deep Dive JUG Saxony Day 2015-10-02Proxy Deep Dive JUG Saxony Day 2015-10-02
Proxy Deep Dive JUG Saxony Day 2015-10-02
 
Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3Lambdas and-streams-s ritter-v3
Lambdas and-streams-s ritter-v3
 
Unit testing of spark applications
Unit testing of spark applicationsUnit testing of spark applications
Unit testing of spark applications
 
Chapel-on-X: Exploring Tasking Runtimes for PGAS Languages
Chapel-on-X: Exploring Tasking Runtimes for PGAS LanguagesChapel-on-X: Exploring Tasking Runtimes for PGAS Languages
Chapel-on-X: Exploring Tasking Runtimes for PGAS Languages
 
Spark Summit EU talk by Nimbus Goehausen
Spark Summit EU talk by Nimbus GoehausenSpark Summit EU talk by Nimbus Goehausen
Spark Summit EU talk by Nimbus Goehausen
 
R and C++
R and C++R and C++
R and C++
 
JDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
JDK8 Lambdas and Streams: Changing The Way You Think When Developing JavaJDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
JDK8 Lambdas and Streams: Changing The Way You Think When Developing Java
 
Kotlin Receiver Types 介紹
Kotlin Receiver Types 介紹Kotlin Receiver Types 介紹
Kotlin Receiver Types 介紹
 
Rxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJavaRxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJava
 
Lambdas : Beyond The Basics
Lambdas : Beyond The BasicsLambdas : Beyond The Basics
Lambdas : Beyond The Basics
 
Introduction to ScalaZ
Introduction to ScalaZIntroduction to ScalaZ
Introduction to ScalaZ
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
 
Java SE 8
Java SE 8Java SE 8
Java SE 8
 
Stream processing from single node to a cluster
Stream processing from single node to a clusterStream processing from single node to a cluster
Stream processing from single node to a cluster
 
How to Think in RxJava Before Reacting
How to Think in RxJava Before ReactingHow to Think in RxJava Before Reacting
How to Think in RxJava Before Reacting
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 

Similaire à Factory Methods And Streams Improvements In JDK 9

JDK 9: The Start of a New Future for Java
JDK 9: The Start of a New Future for JavaJDK 9: The Start of a New Future for Java
JDK 9: The Start of a New Future for JavaSimon Ritter
 
JDBC Next: A New Asynchronous API for Connecting to a Database
JDBC Next: A New Asynchronous API for Connecting to a Database JDBC Next: A New Asynchronous API for Connecting to a Database
JDBC Next: A New Asynchronous API for Connecting to a Database Yolande Poirier
 
JDK 9: Mission Accomplished. What Next For Java?
JDK 9: Mission Accomplished. What Next For Java?JDK 9: Mission Accomplished. What Next For Java?
JDK 9: Mission Accomplished. What Next For Java?Simon Ritter
 
SPCA2013 - SharePoint Nightmares - Coding Patterns and Practices
SPCA2013 - SharePoint Nightmares - Coding Patterns and PracticesSPCA2013 - SharePoint Nightmares - Coding Patterns and Practices
SPCA2013 - SharePoint Nightmares - Coding Patterns and PracticesNCCOMMS
 
New and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
New and cool in OSGi R7 - David Bosschaert & Carsten ZiegelerNew and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
New and cool in OSGi R7 - David Bosschaert & Carsten Ziegelermfrancis
 
Maximize the power of OSGi in AEM
Maximize the power of OSGi in AEM Maximize the power of OSGi in AEM
Maximize the power of OSGi in AEM ICF CIRCUIT
 
Mastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin EdelsonMastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin EdelsonAEM HUB
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling RewriterJustin Edelson
 
55 New Features in JDK 9
55 New Features in JDK 955 New Features in JDK 9
55 New Features in JDK 9Simon Ritter
 
MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0oysteing
 
Oracle DV V4 new features overview
Oracle DV V4 new features overviewOracle DV V4 new features overview
Oracle DV V4 new features overviewPhilippe Lions
 
Getting started with Hadoop, Hive, Spark and Kafka
Getting started with Hadoop, Hive, Spark and KafkaGetting started with Hadoop, Hive, Spark and Kafka
Getting started with Hadoop, Hive, Spark and KafkaEdelweiss Kammermann
 
Leveraging the Latest OSGi R7 Specifications - C Ziegeler & D Bosschaert
Leveraging the Latest OSGi R7 Specifications - C Ziegeler & D BosschaertLeveraging the Latest OSGi R7 Specifications - C Ziegeler & D Bosschaert
Leveraging the Latest OSGi R7 Specifications - C Ziegeler & D Bosschaertmfrancis
 
Functional programming in Java
Functional programming in Java  Functional programming in Java
Functional programming in Java Haim Michael
 
All about Oracle Golden Gate by Udaya Kumar Pyla
All about Oracle Golden Gate by Udaya Kumar PylaAll about Oracle Golden Gate by Udaya Kumar Pyla
All about Oracle Golden Gate by Udaya Kumar PylaAiougVizagChapter
 
REST Development made Easy with ColdFusion Aether
REST Development made Easy with ColdFusion AetherREST Development made Easy with ColdFusion Aether
REST Development made Easy with ColdFusion AetherPavan Kumar
 
20180420 hk-the powerofmysql8
20180420 hk-the powerofmysql820180420 hk-the powerofmysql8
20180420 hk-the powerofmysql8Ivan Ma
 
ASP.Net 5 and C# 6
ASP.Net 5 and C# 6ASP.Net 5 and C# 6
ASP.Net 5 and C# 6Andy Butland
 
Keeping Up with Java: Look at All These New Features!
Keeping Up with Java: Look at All These New Features!Keeping Up with Java: Look at All These New Features!
Keeping Up with Java: Look at All These New Features!VMware Tanzu
 

Similaire à Factory Methods And Streams Improvements In JDK 9 (20)

JDK 9: The Start of a New Future for Java
JDK 9: The Start of a New Future for JavaJDK 9: The Start of a New Future for Java
JDK 9: The Start of a New Future for Java
 
JDBC Next: A New Asynchronous API for Connecting to a Database
JDBC Next: A New Asynchronous API for Connecting to a Database JDBC Next: A New Asynchronous API for Connecting to a Database
JDBC Next: A New Asynchronous API for Connecting to a Database
 
MySQL 8.0.1 DMR
MySQL 8.0.1 DMRMySQL 8.0.1 DMR
MySQL 8.0.1 DMR
 
JDK 9: Mission Accomplished. What Next For Java?
JDK 9: Mission Accomplished. What Next For Java?JDK 9: Mission Accomplished. What Next For Java?
JDK 9: Mission Accomplished. What Next For Java?
 
SPCA2013 - SharePoint Nightmares - Coding Patterns and Practices
SPCA2013 - SharePoint Nightmares - Coding Patterns and PracticesSPCA2013 - SharePoint Nightmares - Coding Patterns and Practices
SPCA2013 - SharePoint Nightmares - Coding Patterns and Practices
 
New and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
New and cool in OSGi R7 - David Bosschaert & Carsten ZiegelerNew and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
New and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
 
Maximize the power of OSGi in AEM
Maximize the power of OSGi in AEM Maximize the power of OSGi in AEM
Maximize the power of OSGi in AEM
 
Mastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin EdelsonMastering the Sling Rewriter by Justin Edelson
Mastering the Sling Rewriter by Justin Edelson
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling Rewriter
 
55 New Features in JDK 9
55 New Features in JDK 955 New Features in JDK 9
55 New Features in JDK 9
 
MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0
 
Oracle DV V4 new features overview
Oracle DV V4 new features overviewOracle DV V4 new features overview
Oracle DV V4 new features overview
 
Getting started with Hadoop, Hive, Spark and Kafka
Getting started with Hadoop, Hive, Spark and KafkaGetting started with Hadoop, Hive, Spark and Kafka
Getting started with Hadoop, Hive, Spark and Kafka
 
Leveraging the Latest OSGi R7 Specifications - C Ziegeler & D Bosschaert
Leveraging the Latest OSGi R7 Specifications - C Ziegeler & D BosschaertLeveraging the Latest OSGi R7 Specifications - C Ziegeler & D Bosschaert
Leveraging the Latest OSGi R7 Specifications - C Ziegeler & D Bosschaert
 
Functional programming in Java
Functional programming in Java  Functional programming in Java
Functional programming in Java
 
All about Oracle Golden Gate by Udaya Kumar Pyla
All about Oracle Golden Gate by Udaya Kumar PylaAll about Oracle Golden Gate by Udaya Kumar Pyla
All about Oracle Golden Gate by Udaya Kumar Pyla
 
REST Development made Easy with ColdFusion Aether
REST Development made Easy with ColdFusion AetherREST Development made Easy with ColdFusion Aether
REST Development made Easy with ColdFusion Aether
 
20180420 hk-the powerofmysql8
20180420 hk-the powerofmysql820180420 hk-the powerofmysql8
20180420 hk-the powerofmysql8
 
ASP.Net 5 and C# 6
ASP.Net 5 and C# 6ASP.Net 5 and C# 6
ASP.Net 5 and C# 6
 
Keeping Up with Java: Look at All These New Features!
Keeping Up with Java: Look at All These New Features!Keeping Up with Java: Look at All These New Features!
Keeping Up with Java: Look at All These New Features!
 

Plus de Simon Ritter

Cloud Native Compiler
Cloud Native CompilerCloud Native Compiler
Cloud Native CompilerSimon Ritter
 
The Art of Java Type Patterns
The Art of Java Type PatternsThe Art of Java Type Patterns
The Art of Java Type PatternsSimon Ritter
 
Java performance monitoring
Java performance monitoringJava performance monitoring
Java performance monitoringSimon Ritter
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java WorkshopSimon Ritter
 
Building a Better JVM
Building a Better JVMBuilding a Better JVM
Building a Better JVMSimon Ritter
 
JDK 14 Lots of New Features
JDK 14 Lots of New FeaturesJDK 14 Lots of New Features
JDK 14 Lots of New FeaturesSimon Ritter
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologySimon Ritter
 
Developing Enterprise Applications Using Java Technology
Developing Enterprise Applications Using Java TechnologyDeveloping Enterprise Applications Using Java Technology
Developing Enterprise Applications Using Java TechnologySimon Ritter
 
Is Java Still Free?
Is Java Still Free?Is Java Still Free?
Is Java Still Free?Simon Ritter
 
Moving Towards JDK 12
Moving Towards JDK 12Moving Towards JDK 12
Moving Towards JDK 12Simon Ritter
 
JDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and BeyondJDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and BeyondSimon Ritter
 
Java Is Still Free
Java Is Still FreeJava Is Still Free
Java Is Still FreeSimon Ritter
 
JDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and BeyondJDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and BeyondSimon Ritter
 
JDK 9 and JDK 10 Deep Dive
JDK 9 and JDK 10 Deep DiveJDK 9 and JDK 10 Deep Dive
JDK 9 and JDK 10 Deep DiveSimon Ritter
 
Java Support: What's changing
Java Support:  What's changingJava Support:  What's changing
Java Support: What's changingSimon Ritter
 
JDK 9: Migrating Applications
JDK 9: Migrating ApplicationsJDK 9: Migrating Applications
JDK 9: Migrating ApplicationsSimon Ritter
 
Building a Brain with Raspberry Pi and Zulu Embedded JVM
Building a Brain with Raspberry Pi and Zulu Embedded JVMBuilding a Brain with Raspberry Pi and Zulu Embedded JVM
Building a Brain with Raspberry Pi and Zulu Embedded JVMSimon Ritter
 
JDK 9: 55 New Features
JDK 9: 55 New FeaturesJDK 9: 55 New Features
JDK 9: 55 New FeaturesSimon Ritter
 

Plus de Simon Ritter (20)

Cloud Native Compiler
Cloud Native CompilerCloud Native Compiler
Cloud Native Compiler
 
Java On CRaC
Java On CRaCJava On CRaC
Java On CRaC
 
The Art of Java Type Patterns
The Art of Java Type PatternsThe Art of Java Type Patterns
The Art of Java Type Patterns
 
Java performance monitoring
Java performance monitoringJava performance monitoring
Java performance monitoring
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java Workshop
 
Building a Better JVM
Building a Better JVMBuilding a Better JVM
Building a Better JVM
 
JDK 14 Lots of New Features
JDK 14 Lots of New FeaturesJDK 14 Lots of New Features
JDK 14 Lots of New Features
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
 
Developing Enterprise Applications Using Java Technology
Developing Enterprise Applications Using Java TechnologyDeveloping Enterprise Applications Using Java Technology
Developing Enterprise Applications Using Java Technology
 
Is Java Still Free?
Is Java Still Free?Is Java Still Free?
Is Java Still Free?
 
Moving Towards JDK 12
Moving Towards JDK 12Moving Towards JDK 12
Moving Towards JDK 12
 
JDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and BeyondJDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and Beyond
 
Java Is Still Free
Java Is Still FreeJava Is Still Free
Java Is Still Free
 
JDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and BeyondJDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and Beyond
 
JDK 9 and JDK 10 Deep Dive
JDK 9 and JDK 10 Deep DiveJDK 9 and JDK 10 Deep Dive
JDK 9 and JDK 10 Deep Dive
 
JDK 9 Deep Dive
JDK 9 Deep DiveJDK 9 Deep Dive
JDK 9 Deep Dive
 
Java Support: What's changing
Java Support:  What's changingJava Support:  What's changing
Java Support: What's changing
 
JDK 9: Migrating Applications
JDK 9: Migrating ApplicationsJDK 9: Migrating Applications
JDK 9: Migrating Applications
 
Building a Brain with Raspberry Pi and Zulu Embedded JVM
Building a Brain with Raspberry Pi and Zulu Embedded JVMBuilding a Brain with Raspberry Pi and Zulu Embedded JVM
Building a Brain with Raspberry Pi and Zulu Embedded JVM
 
JDK 9: 55 New Features
JDK 9: 55 New FeaturesJDK 9: 55 New Features
JDK 9: 55 New Features
 

Dernier

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 

Dernier (20)

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

Factory Methods And Streams Improvements In JDK 9

  • 1. © Copyright Azul Systems 2017 1
  • 2. © Copyright Azul Systems 2017 © Copyright Azul Systems 2015 @speakjava What’s New For Developers In JDK 9 Simon Ritter Deputy CTO, Azul Systems 2
  • 3. © Copyright Azul Systems 2017 Convenience Factory Methods For Collections (JEP 269)
  • 4. © Copyright Azul Systems 2017 Factory Methods For Collections (JEP 269)  The problem: – Creating a small unmodifiable collection is verbose 4 Set<String> set = new HashSet<>(); set.add("a"); set.add("b"); set.add("c"); set = Collections.unmodifiableSet(set);
  • 5. © Copyright Azul Systems 2017 Factory Methods For Collections (JEP 269)  Static methods added to List, Set and Map interfaces – Create compact, immutable instances – 0 to 10 element overloaded versions – Varargs version for arbitary number of elements 5 Set<String> set = Set.of("a", "b", "c"); List<String> list = List.of("a", "b", "c"); Map<String, String> map = Map.of(“k1”, “v1”, “k2”, “v2”); Map<String, String> map = Map.ofEntries( entry(“k1”, “v1”), entry(“k2”, “v2”));
  • 6. © Copyright Azul Systems 2017 New APIs For Streams
  • 7. © Copyright Azul Systems 2017 dropWhile/takeWhile  Like skip() and limit(), but taking a Predicate – takeWhile can convert an infinite stream to a finite one – Be careful of unordered streams missing values 7 list.stream() .dropWhile(s -> s.charAt(0) < ‘e') .forEach(System.out::println); List<String> list = List.of("alpha", "bravo", "charlie", "delta", "echo", "foxtrot"); list.stream() .takeWhile(s -> s.length() == 5) .forEach(System.out::println); alpha bravo delta echo foxtrot
  • 8. © Copyright Azul Systems 2017 Improved Iteration  iterate(seed, hasNext, next) – Can be used like the classic for loop 8 Initial value Predicate UnaryOperator IntStream.iterate(0, i -> i < 10, i -> ++i) .forEach(System.out::println); IntStream.iterate(0, i -> i < 10, i -> i++) .forEach(System.out::println); Infinite stream
  • 9. © Copyright Azul Systems 2017 New APIs For Optional
  • 10. © Copyright Azul Systems 2017 New Methods  ifPresentOrElse(Consumer action, Runnable emptyAction) – If a value is present call accept() on action with the value – Otherwise, run the emptyAction  Not in a separate thread  or(Supplier<? extends Optional<? extends T>> supplier) – Return the Optional if there is a value – Otherwise, return a new Optional created by the Supplier  stream() – Returns a stream of zero or one element 10
  • 11. © Copyright Azul Systems 2017 Langauge Changes (JEP 213)
  • 12. © Copyright Azul Systems 2017 Milling Project Coin  Single underscore is now a reserved word – No longer usable as an identifier – Two or more underscores still works  Allow @SafeVarargs on private instance methods – In addition to constructors, final and static methods 12
  • 13. © Copyright Azul Systems 2017 Milling Project Coin  Private methods are now permitted in interfaces – Separate common code for default and static methods 13 public interface MyInterface { default int getX() { return getNum() * 2; }; static int getY() { return getNum() * 4; } private static int getNum() { return 12; } }
  • 14. © Copyright Azul Systems 2017 Milling Project Coin  Effectively final variables in try-with-resources 14 BufferedReader reader = new BufferedReader(new FileReader("/tmp/foo.txt")); try (BufferedReader myReader = reader) { myReader.lines() .forEach(System.out::println); } JDK 8 try (reader) { reader.lines() .forEach(System.out::println); }
  • 15. © Copyright Azul Systems 2017 Milling Project Coin  Diamond operator with anonymous classes – Type inference can infer a non-denotable type – If the type inferred can be denotable you can use <> 15 public abstract class Processor<T> { abstract void use(T value); } Processor<String> processor = new Processor<>() { @Override void use(String value) { // Some stuff } };
  • 16. © Copyright Azul Systems 2017 More Concurrency: Reactive Streams (JEP 266)
  • 17. © Copyright Azul Systems 2017 The Problem 17 Publisher Subscriber Process Process Process Process BLOCK
  • 18. © Copyright Azul Systems 2017 Reactive Streams: Flow API  Set of interfaces  Publisher – Producer of items to be received by Subscribers  Subscriber – Receiver of messages  Processor – Both a Publisher and Subscriber (chaining)  Subscription – Message control linking a Publisher and Subscriber 18
  • 19. © Copyright Azul Systems 2017 Reactive Streams: Flow API  Publisher – subscribe(Subscriber)  Subscriber – OnSubscribe(Subscription) – onNext(T item) – onComplete() / onError(Throwable)  Subscription – request(long) – cancel() 19
  • 20. © Copyright Azul Systems 2017 Solution 20 Publisher Subscriber Subscription request(4) subscribe onSubscribe onItem onItem onItem onItem request(2)
  • 21. © Copyright Azul Systems 2017 Conclusions  JDK 9 adds some useful features – Minor language changes – Small updates to streams API and Optional – Factory methods for collections – Reactive stream API is probably biggest new feature  More not covered here – CompletableFuture additions – Stack walking API – Process API enhancements 21
  • 22. © Copyright Azul Systems 2017 Quick Poll  How excited are you about the release of JDK 9? a. Can't wait to get using all those great new features b. Looks interesting, but I’m pretty happy with JDK 8 c. The module system looks scarey d. When's JDK 10 being released? 22
  • 23. © Copyright Azul Systems 2017 © Copyright Azul Systems 2015 @speakjava Thank You! zulu.org Free certified OpenJDK binaries Simon Ritter Deputy CTO, Azul Systems 23