SlideShare a Scribd company logo
1 of 43
Download to read offline
Retro Gaming With Lambdas
Stephen Chin (@steveonjava)
Java Technology Ambassador
JavaOne Content Chair
JDK 8 Feature Overview
Innovation

Java for Everyone

Client

• Lambda aka Closures
• Language Interop
• Nashorn

• Profiles for constrained devices
• JSR 310 - Date & Time APIs
• Non-Gregorian calendars
• Unicode 6.2
• ResourceBundle.
• BCP47 locale matching
• Globalization & Accessibility

• Deployment enhancements
• JavaFX 8
• Java SE Embedded support
• Enhanced HTML5 support
• 3D shapes and attributes
• Printing

Core Libraries
• Parallel operations for core
collections APIs
• Improvements in functionality
• Improved type inference

General Goodness
• JVM enhancements
• No PermGen limitations
• Performance lmprovements

Tools
• Compiler control & logging
• JSR 308 - Annotations on
Java Type
• Native app bundling
• App Store Bundling tools

Security
•
•
•
•
•

Limited doPrivilege
NSA Suite B algorithm support
SNI Server Side support
DSA updated to FIPS186-3
AEAD JSSE CipherSuites
Coordinated Platform Upgrade with Lambda
>

Language



>

Libraries



>

Lambda Expressions (closures)
Interface Evolution with default methods
Bulk data operations on Collections
More library support for parallelism

JVM



Default methods
Enhancements to invokedynamic
Download JDK 8 Early Access Release

4
IDE Support for Lambdas

5
for (Shape s : shapes) {
if (s.getColor() == BLUE)
s.setColor(RED);
}
shapes.forEach(s -> {
if (s.getColor() == BLUE)
s.setColor(RED);
});
Extension Methods
interface Collection<T> {
default void forEach(Block<T> action) {
Objects.requireNonNull(action);
for (T t : this)
action.apply(t);
}
// Rest of Collection methods…
}
Lambda Syntax
>

(int a, int b) -> { return a + b; }

>

(a, b) -> a + b

>

a -> a * a

>

() -> a

>

() -> { System.out.println("done"); }
8
Method References
>

Objects::toString

obj -> Objects.toString(obj)

>

Object::toString

obj -> obj.toString()

>

obj::toString

() -> obj.toString()

>

Object::new

() -> new Object()

9
Functional Interfaces
@FunctionalInterface
@FunctionalInterface
interface Sum {
int add(int a, int b);
}
sum = (a, b) -> a + b;
sum = Integer::sum;
10
Vanishing Circles

11
Application Skeleton
public class VanishingCircles extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Vanishing Circles");
Group root = new Group();
Scene scene = new Scene(root, 800, 600, Color.BLACK);
[create the circles…]
root.getChildren().addAll(circles);
primaryStage.setScene(scene);
primaryStage.show();
[begin the animation…]
}
}
Create the Circles
List<Circle> circles = new ArrayList<Circle>();
for (int i = 0; i < 50; i++) {
final Circle circle = new Circle(150);
circle.setCenterX(Math.random() * 800);
circle.setCenterY(Math.random() * 600);
circle.setFill(new Color(Math.random(), Math.random(),
Math.random(), .2));
circle.setEffect(new BoxBlur(10, 10, 3));
circle.setStroke(Color.WHITE);
[setup binding…]
[setup event listeners…]
circles.add(circle);
}
13
Create the Circles
List<Circle> circles = Streams.generate(() -> {
final Circle circle = new Circle(150);
circle.setCenterX(Math.random() * 800);
circle.setCenterY(Math.random() * 600);
circle.setFill(new Color(Math.random(), Math.random(),
Math.random(), .2));
circle.setEffect(new BoxBlur(10, 10, 3));
circle.setStroke(Color.WHITE);
[setup binding…]
[setup event listeners…]
return circle;
}).limit(50).collect(Collectors.toList());
14
Setup Binding
circle.strokeWidthProperty().bind(Bindings
.when(circle.hoverProperty())
.then(4)
.otherwise(0)
);

15
Setup Event Listeners
circle.addEventHandler(MouseEvent.MOUSE_CLICKED,
new EventHandler<MouseEvent>() {
public void handle(MouseEvent t) {
KeyValue collapse = new KeyValue(circle.radiusProperty(), 0);
new Timeline(new KeyFrame(Duration.seconds(3),
collapse)).play();
}
});

16
Lambda-ized Event Listeners
circle.addEventHandler(MouseEvent.MOUSE_CLICKED, e -> {
KeyValue collapse = new KeyValue(circle.radiusProperty(), 0);
new Timeline(new KeyFrame(Duration.seconds(3),
collapse)).play();
});

17
Begin the Animation
Timeline moveCircles = new Timeline();
for (Circle circle : circles) {
KeyValue moveX = new KeyValue(circle.centerXProperty(),
Math.random() * 800);
KeyValue moveY = new KeyValue(circle.centerYProperty(),
Math.random() * 600);
moveCircles.getKeyFrames().add(new
KeyFrame(Duration.seconds(40),
moveX, moveY));
}
moveCircles.play();
18
Lambda-ized Begin the Animation
Timeline moveCircles = new Timeline();
circles.forEach(circle -> {
KeyValue moveX = new KeyValue(circle.centerXProperty(),
Math.random() * 800);
KeyValue moveY = new KeyValue(circle.centerYProperty(),
Math.random() * 600);
moveCircles.getKeyFrames().add(new KeyFrame(Duration.seconds(40),
moveX, moveY));
});
moveCircles.play();

19
Mary Had a Little Lambda

Mary had a little lambda
Whose fleece was white as snow
And everywhere that Mary went
Lambda was sure to go!

https://github.com/steveonjava/MaryHadALittleLambda
Generating Streams
From a collection:
> anyCollection.stream();
Known set of objects:
> Stream.of("bananas", "oranges", "apples");
Numeric range:
> IntStream.range(0, 50)
Iteratively:
> Stream.iterate(Color.RED,
>
c -> Color.hsb(c.getHue() + .1, c.getSaturation(),
>
c.getBrightness()));
21
Let's Create Some Barn Animals!
SpriteView tail = s.getAnimals().isEmpty() ?
s : s.getAnimals().get(s.getAnimals().size() - 1);
Stream.iterate(tail, SpriteView.Lamb::new)
.substream(1, 8)
.forEach(s.getAnimals()::add);

22
23
Filtering Streams
Predicate Expression
> public interface Predicate<T> {
>
public boolean test(T t);
> }
Filter out minors
> adults = attendees.filter(a -> a.getAge() >= 1.8)

24
Rainbow-colored Lambs!
s.getAnimals().stream()
.filter(a -> a.getNumber() % 4 == 2)
.forEach(a -> a.setColor(Color.YELLOW));
s.getAnimals().stream()
.filter(a -> a.getNumber() % 4 == 3)
.forEach(a -> a.setColor(Color.CYAN));
s.getAnimals().stream()
.filter(a -> a.getNumber() % 4 == 0)
.forEach(a -> a.setColor(Color.GREEN));
25
26
Filtering Collections
Collection.removeIf
> Removes all elements that match the predicate
List.replaceAll
> In-place filtering and replacement using an unary operator
ObservableCollection.filtered
> Returns a list filtered by a predicate this is also Observable

27
Picky Eaters…
Predicate<SpriteView> pure =
a -> a.getColor() == null;
mealsServed.set(mealsServed.get() +
s.getAnimals().filtered(pure).size()
);
s.getAnimals().removeIf(pure);
28
29
Mapping Streams
Applies a Map Function to each element:
> Function<? super T, ? extends R>
Result: List is the same size, but may be a different type.

30
Single Map
s.getAnimals().setAll(s.getAnimals()
.stream()
.map(sv -> new Eggs(sv.getFollowing())
.collect(Collectors.toList())
);

31
Or a Double Map!
s.getAnimals().setAll(s.getAnimals()
.stream()
.map(SpriteView::getFollowing)
.map(Eggs::new)
.collect(Collectors.toList())
);

32
33
Flat Map
Applies a One-to-Many Map Function to each element:
> Function<? super T, ? extends Stream<? extends R>>
And then flattens the result into a single stream.
Result: The list may get longer and the type may be different.

34
Hatching Eggs
s.getAnimals().setAll(s.getAnimals()
.stream()
.flatMap(SpriteView.Eggs::hatch)
.collect(Collectors.toList())
);

35
36
Reduce
Reduces a list to a single element given:
> Identity: T
> Accumulator: BinaryOperator<T>
Result: List of the same type, but only 1 element left.

37
And the (formerly little) Fox ate them all!
Double mealSize = shepherd.getAnimals()
.stream()
.map(SpriteView::getScaleX)
.reduce(0.0, Double::sum);
setScaleX(getScaleX() + mealSize * .2);
setScaleY(getScaleY() + mealSize * .2);
shepherd.getAnimals().clear();

38
39
Mary Had a Little Lambda Project
>
>

Open-source project to demonstrate lambda features
Visual representation of streams, filters, and maps
https://github.com/steveonjava/MaryHadALittleLambda

40
NightHacking Tour

Stephen Chin
tweet: @steveonjava
blog: http://steveonjava.com

Real Geeks
Live Hacking
nighthacking.com
Graphics Image Credits
>

>

>

>

>

>

Mary image by Terra-chan:
http://www.rpgmakervx.net/index.php?showtopic=29404
Lamb image by Mack:
http://www.rpgmakervx.net/index.php?showtopic=15704
Chicken, Church, Barn, and Coop image by LovelyBlue:
http://l0velyblue.deviantart.com/art/Chicken-203764427
Fox image by PinedaVX:
http://www.rpgmakervx.net/index.php?showtopic=9422
Nest image derived from Lokilech's Amselnest:
http://commons.wikimedia.org/wiki/File:Amselnest_lokilech.jpg
Background image by Victor Szalvay:
http://www.flickr.com/photos/55502991@N00/172603855
42
Safe Harbor Statement
The preceding is intended to outline our general product
direction. It is intended for information purposes only, and
may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality,
and should not be relied upon in making purchasing
decisions. The development, release, and timing of any
features or functionality described for Oracle’s products
remains at the sole discretion of Oracle.

More Related Content

What's hot

V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at...
V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at...V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at...
V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at...DevClub_lv
 
The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212Mahmoud Samir Fayed
 
λ | Lenses
λ | Lensesλ | Lenses
λ | LensesOpen-IT
 
ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine Aleksandar Prokopec
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Developmentvito jeng
 
Scalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduceScalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduceLivePerson
 
Should I Use Scalding or Scoobi or Scrunch?
Should I Use Scalding or Scoobi or Scrunch? Should I Use Scalding or Scoobi or Scrunch?
Should I Use Scalding or Scoobi or Scrunch? DataWorks Summit
 
JPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream APIJPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream APItvaleev
 
Scalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of codeScalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of codeKonrad Malawski
 
関数プログラミングことはじめ revival
関数プログラミングことはじめ revival関数プログラミングことはじめ revival
関数プログラミングことはじめ revivalNaoki Kitora
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao IntroductionBooch Lin
 
The Ring programming language version 1.7 book - Part 57 of 196
The Ring programming language version 1.7 book - Part 57 of 196The Ring programming language version 1.7 book - Part 57 of 196
The Ring programming language version 1.7 book - Part 57 of 196Mahmoud Samir Fayed
 
Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using RoomNelson Glauber Leal
 
The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88Mahmoud Samir Fayed
 
Type classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritanceType classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritanceAlexey Raga
 

What's hot (20)

V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at...
V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at...V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at...
V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at...
 
The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212
 
λ | Lenses
λ | Lensesλ | Lenses
λ | Lenses
 
ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Development
 
Scalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduceScalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduce
 
Beyond Scala Lens
Beyond Scala LensBeyond Scala Lens
Beyond Scala Lens
 
Should I Use Scalding or Scoobi or Scrunch?
Should I Use Scalding or Scoobi or Scrunch? Should I Use Scalding or Scoobi or Scrunch?
Should I Use Scalding or Scoobi or Scrunch?
 
Corona sdk
Corona sdkCorona sdk
Corona sdk
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
JPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream APIJPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream API
 
Scala for Jedi
Scala for JediScala for Jedi
Scala for Jedi
 
Scalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of codeScalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of code
 
関数プログラミングことはじめ revival
関数プログラミングことはじめ revival関数プログラミングことはじめ revival
関数プログラミングことはじめ revival
 
Alternate JVM Languages
Alternate JVM LanguagesAlternate JVM Languages
Alternate JVM Languages
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
 
The Ring programming language version 1.7 book - Part 57 of 196
The Ring programming language version 1.7 book - Part 57 of 196The Ring programming language version 1.7 book - Part 57 of 196
The Ring programming language version 1.7 book - Part 57 of 196
 
Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using Room
 
The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88
 
Type classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritanceType classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritance
 

Similar to Retro gaming with lambdas stephen chin

Mary Had a Little λ (QCon)
Mary Had a Little λ (QCon)Mary Had a Little λ (QCon)
Mary Had a Little λ (QCon)Stephen Chin
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Leonardo Borges
 
RESTful API using scalaz (3)
RESTful API using scalaz (3)RESTful API using scalaz (3)
RESTful API using scalaz (3)Yeshwanth Kumar
 
CON5423-GS-Collections-and-Java-8-Functional-Fluent-Friendly-and-Fun.pptx
CON5423-GS-Collections-and-Java-8-Functional-Fluent-Friendly-and-Fun.pptxCON5423-GS-Collections-and-Java-8-Functional-Fluent-Friendly-and-Fun.pptx
CON5423-GS-Collections-and-Java-8-Functional-Fluent-Friendly-and-Fun.pptxskypy045
 
Collections in Java
Collections in JavaCollections in Java
Collections in JavaKhasim Cise
 
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~Atsushi Torikoshi
 
Data Structures in javaScript 2015
Data Structures in javaScript 2015Data Structures in javaScript 2015
Data Structures in javaScript 2015Nir Kaufman
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196Mahmoud Samir Fayed
 
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...Fons Sonnemans
 
Python seaborn cheat_sheet
Python seaborn cheat_sheetPython seaborn cheat_sheet
Python seaborn cheat_sheetNishant Upadhyay
 
The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 54 of 184
The Ring programming language version 1.5.3 book - Part 54 of 184The Ring programming language version 1.5.3 book - Part 54 of 184
The Ring programming language version 1.5.3 book - Part 54 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31Mahmoud Samir Fayed
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 

Similar to Retro gaming with lambdas stephen chin (20)

Mary Had a Little λ (QCon)
Mary Had a Little λ (QCon)Mary Had a Little λ (QCon)
Mary Had a Little λ (QCon)
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015
 
collections
collectionscollections
collections
 
RESTful API using scalaz (3)
RESTful API using scalaz (3)RESTful API using scalaz (3)
RESTful API using scalaz (3)
 
CON5423-GS-Collections-and-Java-8-Functional-Fluent-Friendly-and-Fun.pptx
CON5423-GS-Collections-and-Java-8-Functional-Fluent-Friendly-and-Fun.pptxCON5423-GS-Collections-and-Java-8-Functional-Fluent-Friendly-and-Fun.pptx
CON5423-GS-Collections-and-Java-8-Functional-Fluent-Friendly-and-Fun.pptx
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
 
Collections
CollectionsCollections
Collections
 
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
 
Spark workshop
Spark workshopSpark workshop
Spark workshop
 
Coding in Style
Coding in StyleCoding in Style
Coding in Style
 
Data Structures in javaScript 2015
Data Structures in javaScript 2015Data Structures in javaScript 2015
Data Structures in javaScript 2015
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196
 
Collections
CollectionsCollections
Collections
 
Fp java8
Fp java8Fp java8
Fp java8
 
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
 
Python seaborn cheat_sheet
Python seaborn cheat_sheetPython seaborn cheat_sheet
Python seaborn cheat_sheet
 
The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184
 
The Ring programming language version 1.5.3 book - Part 54 of 184
The Ring programming language version 1.5.3 book - Part 54 of 184The Ring programming language version 1.5.3 book - Part 54 of 184
The Ring programming language version 1.5.3 book - Part 54 of 184
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 

More from NLJUG

The future of Web-Scale - Johan Tillema, Rene Boere & Chris Quach
The future of Web-Scale - Johan Tillema, Rene Boere & Chris QuachThe future of Web-Scale - Johan Tillema, Rene Boere & Chris Quach
The future of Web-Scale - Johan Tillema, Rene Boere & Chris QuachNLJUG
 
Speedy perception trumps speedy reception–smart asynchronous interactions - L...
Speedy perception trumps speedy reception–smart asynchronous interactions - L...Speedy perception trumps speedy reception–smart asynchronous interactions - L...
Speedy perception trumps speedy reception–smart asynchronous interactions - L...NLJUG
 
Decoding the airspace above you with Java and $7 hardware - Bert Jan Schrijver
Decoding the airspace above you with Java and $7 hardware - Bert Jan SchrijverDecoding the airspace above you with Java and $7 hardware - Bert Jan Schrijver
Decoding the airspace above you with Java and $7 hardware - Bert Jan SchrijverNLJUG
 
Using Docker to Develop, Test and Run Maven Projects - Wouter Danes
Using Docker to Develop, Test and Run Maven Projects - Wouter DanesUsing Docker to Develop, Test and Run Maven Projects - Wouter Danes
Using Docker to Develop, Test and Run Maven Projects - Wouter DanesNLJUG
 
Kill the mutants and test your tests - Roy van Rijn
Kill the mutants and test your tests - Roy van RijnKill the mutants and test your tests - Roy van Rijn
Kill the mutants and test your tests - Roy van RijnNLJUG
 
Real-time user interfaces - sosm gewoon makkelijker - Allard Buijze
Real-time user interfaces - sosm gewoon makkelijker - Allard BuijzeReal-time user interfaces - sosm gewoon makkelijker - Allard Buijze
Real-time user interfaces - sosm gewoon makkelijker - Allard BuijzeNLJUG
 
The end of traditional enterprise IT - ING's journey to the next generation I...
The end of traditional enterprise IT - ING's journey to the next generation I...The end of traditional enterprise IT - ING's journey to the next generation I...
The end of traditional enterprise IT - ING's journey to the next generation I...NLJUG
 
Performance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersPerformance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersNLJUG
 
Introduction to Reactive with Play and Akka - Markus Jura
Introduction to Reactive with Play and Akka - Markus JuraIntroduction to Reactive with Play and Akka - Markus Jura
Introduction to Reactive with Play and Akka - Markus JuraNLJUG
 
Web-scale op basis van Hadoop en Akka Reactive Streams - Johan Tillema, Rene ...
Web-scale op basis van Hadoop en Akka Reactive Streams - Johan Tillema, Rene ...Web-scale op basis van Hadoop en Akka Reactive Streams - Johan Tillema, Rene ...
Web-scale op basis van Hadoop en Akka Reactive Streams - Johan Tillema, Rene ...NLJUG
 
Workshop angular dart presentatie - Atos
Workshop angular dart presentatie - AtosWorkshop angular dart presentatie - Atos
Workshop angular dart presentatie - AtosNLJUG
 
Workshop spring boot presentatie - Atos
Workshop spring boot presentatie - AtosWorkshop spring boot presentatie - Atos
Workshop spring boot presentatie - AtosNLJUG
 
Cultivating the jenkins job jungle with groovy - Patrick van Dissel
Cultivating the jenkins job jungle with groovy - Patrick van DisselCultivating the jenkins job jungle with groovy - Patrick van Dissel
Cultivating the jenkins job jungle with groovy - Patrick van DisselNLJUG
 
Rethink your architecture - Marten Deinum
Rethink your architecture - Marten DeinumRethink your architecture - Marten Deinum
Rethink your architecture - Marten DeinumNLJUG
 
Evolutionary Algorithms: the key to solving complex Java puzzles! - Bas knopper
Evolutionary Algorithms: the key to solving complex Java puzzles! - Bas knopperEvolutionary Algorithms: the key to solving complex Java puzzles! - Bas knopper
Evolutionary Algorithms: the key to solving complex Java puzzles! - Bas knopperNLJUG
 
Modularity and Domain Driven Design; a killer Combination? - Tom de Wolf & St...
Modularity and Domain Driven Design; a killer Combination? - Tom de Wolf & St...Modularity and Domain Driven Design; a killer Combination? - Tom de Wolf & St...
Modularity and Domain Driven Design; a killer Combination? - Tom de Wolf & St...NLJUG
 
Apache Wicket: 10 jaar en verder - Martijn Dashorst
Apache Wicket: 10 jaar en verder - Martijn DashorstApache Wicket: 10 jaar en verder - Martijn Dashorst
Apache Wicket: 10 jaar en verder - Martijn DashorstNLJUG
 
Opening - Bert Ertman
Opening - Bert ErtmanOpening - Bert Ertman
Opening - Bert ErtmanNLJUG
 
Returning the right results - Jettro Coenradie
Returning the right results - Jettro CoenradieReturning the right results - Jettro Coenradie
Returning the right results - Jettro CoenradieNLJUG
 
Reactive programming met Java 8 en Java EE 7 - Martijn Blankestijn
Reactive programming met Java 8 en Java EE 7 - Martijn BlankestijnReactive programming met Java 8 en Java EE 7 - Martijn Blankestijn
Reactive programming met Java 8 en Java EE 7 - Martijn BlankestijnNLJUG
 

More from NLJUG (20)

The future of Web-Scale - Johan Tillema, Rene Boere & Chris Quach
The future of Web-Scale - Johan Tillema, Rene Boere & Chris QuachThe future of Web-Scale - Johan Tillema, Rene Boere & Chris Quach
The future of Web-Scale - Johan Tillema, Rene Boere & Chris Quach
 
Speedy perception trumps speedy reception–smart asynchronous interactions - L...
Speedy perception trumps speedy reception–smart asynchronous interactions - L...Speedy perception trumps speedy reception–smart asynchronous interactions - L...
Speedy perception trumps speedy reception–smart asynchronous interactions - L...
 
Decoding the airspace above you with Java and $7 hardware - Bert Jan Schrijver
Decoding the airspace above you with Java and $7 hardware - Bert Jan SchrijverDecoding the airspace above you with Java and $7 hardware - Bert Jan Schrijver
Decoding the airspace above you with Java and $7 hardware - Bert Jan Schrijver
 
Using Docker to Develop, Test and Run Maven Projects - Wouter Danes
Using Docker to Develop, Test and Run Maven Projects - Wouter DanesUsing Docker to Develop, Test and Run Maven Projects - Wouter Danes
Using Docker to Develop, Test and Run Maven Projects - Wouter Danes
 
Kill the mutants and test your tests - Roy van Rijn
Kill the mutants and test your tests - Roy van RijnKill the mutants and test your tests - Roy van Rijn
Kill the mutants and test your tests - Roy van Rijn
 
Real-time user interfaces - sosm gewoon makkelijker - Allard Buijze
Real-time user interfaces - sosm gewoon makkelijker - Allard BuijzeReal-time user interfaces - sosm gewoon makkelijker - Allard Buijze
Real-time user interfaces - sosm gewoon makkelijker - Allard Buijze
 
The end of traditional enterprise IT - ING's journey to the next generation I...
The end of traditional enterprise IT - ING's journey to the next generation I...The end of traditional enterprise IT - ING's journey to the next generation I...
The end of traditional enterprise IT - ING's journey to the next generation I...
 
Performance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersPerformance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen Borgers
 
Introduction to Reactive with Play and Akka - Markus Jura
Introduction to Reactive with Play and Akka - Markus JuraIntroduction to Reactive with Play and Akka - Markus Jura
Introduction to Reactive with Play and Akka - Markus Jura
 
Web-scale op basis van Hadoop en Akka Reactive Streams - Johan Tillema, Rene ...
Web-scale op basis van Hadoop en Akka Reactive Streams - Johan Tillema, Rene ...Web-scale op basis van Hadoop en Akka Reactive Streams - Johan Tillema, Rene ...
Web-scale op basis van Hadoop en Akka Reactive Streams - Johan Tillema, Rene ...
 
Workshop angular dart presentatie - Atos
Workshop angular dart presentatie - AtosWorkshop angular dart presentatie - Atos
Workshop angular dart presentatie - Atos
 
Workshop spring boot presentatie - Atos
Workshop spring boot presentatie - AtosWorkshop spring boot presentatie - Atos
Workshop spring boot presentatie - Atos
 
Cultivating the jenkins job jungle with groovy - Patrick van Dissel
Cultivating the jenkins job jungle with groovy - Patrick van DisselCultivating the jenkins job jungle with groovy - Patrick van Dissel
Cultivating the jenkins job jungle with groovy - Patrick van Dissel
 
Rethink your architecture - Marten Deinum
Rethink your architecture - Marten DeinumRethink your architecture - Marten Deinum
Rethink your architecture - Marten Deinum
 
Evolutionary Algorithms: the key to solving complex Java puzzles! - Bas knopper
Evolutionary Algorithms: the key to solving complex Java puzzles! - Bas knopperEvolutionary Algorithms: the key to solving complex Java puzzles! - Bas knopper
Evolutionary Algorithms: the key to solving complex Java puzzles! - Bas knopper
 
Modularity and Domain Driven Design; a killer Combination? - Tom de Wolf & St...
Modularity and Domain Driven Design; a killer Combination? - Tom de Wolf & St...Modularity and Domain Driven Design; a killer Combination? - Tom de Wolf & St...
Modularity and Domain Driven Design; a killer Combination? - Tom de Wolf & St...
 
Apache Wicket: 10 jaar en verder - Martijn Dashorst
Apache Wicket: 10 jaar en verder - Martijn DashorstApache Wicket: 10 jaar en verder - Martijn Dashorst
Apache Wicket: 10 jaar en verder - Martijn Dashorst
 
Opening - Bert Ertman
Opening - Bert ErtmanOpening - Bert Ertman
Opening - Bert Ertman
 
Returning the right results - Jettro Coenradie
Returning the right results - Jettro CoenradieReturning the right results - Jettro Coenradie
Returning the right results - Jettro Coenradie
 
Reactive programming met Java 8 en Java EE 7 - Martijn Blankestijn
Reactive programming met Java 8 en Java EE 7 - Martijn BlankestijnReactive programming met Java 8 en Java EE 7 - Martijn Blankestijn
Reactive programming met Java 8 en Java EE 7 - Martijn Blankestijn
 

Recently uploaded

Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 

Recently uploaded (20)

Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 

Retro gaming with lambdas stephen chin

  • 1. Retro Gaming With Lambdas Stephen Chin (@steveonjava) Java Technology Ambassador JavaOne Content Chair
  • 2. JDK 8 Feature Overview Innovation Java for Everyone Client • Lambda aka Closures • Language Interop • Nashorn • Profiles for constrained devices • JSR 310 - Date & Time APIs • Non-Gregorian calendars • Unicode 6.2 • ResourceBundle. • BCP47 locale matching • Globalization & Accessibility • Deployment enhancements • JavaFX 8 • Java SE Embedded support • Enhanced HTML5 support • 3D shapes and attributes • Printing Core Libraries • Parallel operations for core collections APIs • Improvements in functionality • Improved type inference General Goodness • JVM enhancements • No PermGen limitations • Performance lmprovements Tools • Compiler control & logging • JSR 308 - Annotations on Java Type • Native app bundling • App Store Bundling tools Security • • • • • Limited doPrivilege NSA Suite B algorithm support SNI Server Side support DSA updated to FIPS186-3 AEAD JSSE CipherSuites
  • 3. Coordinated Platform Upgrade with Lambda > Language   > Libraries   > Lambda Expressions (closures) Interface Evolution with default methods Bulk data operations on Collections More library support for parallelism JVM   Default methods Enhancements to invokedynamic
  • 4. Download JDK 8 Early Access Release 4
  • 5. IDE Support for Lambdas 5
  • 6. for (Shape s : shapes) { if (s.getColor() == BLUE) s.setColor(RED); } shapes.forEach(s -> { if (s.getColor() == BLUE) s.setColor(RED); });
  • 7. Extension Methods interface Collection<T> { default void forEach(Block<T> action) { Objects.requireNonNull(action); for (T t : this) action.apply(t); } // Rest of Collection methods… }
  • 8. Lambda Syntax > (int a, int b) -> { return a + b; } > (a, b) -> a + b > a -> a * a > () -> a > () -> { System.out.println("done"); } 8
  • 9. Method References > Objects::toString obj -> Objects.toString(obj) > Object::toString obj -> obj.toString() > obj::toString () -> obj.toString() > Object::new () -> new Object() 9
  • 10. Functional Interfaces @FunctionalInterface @FunctionalInterface interface Sum { int add(int a, int b); } sum = (a, b) -> a + b; sum = Integer::sum; 10
  • 12. Application Skeleton public class VanishingCircles extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Vanishing Circles"); Group root = new Group(); Scene scene = new Scene(root, 800, 600, Color.BLACK); [create the circles…] root.getChildren().addAll(circles); primaryStage.setScene(scene); primaryStage.show(); [begin the animation…] } }
  • 13. Create the Circles List<Circle> circles = new ArrayList<Circle>(); for (int i = 0; i < 50; i++) { final Circle circle = new Circle(150); circle.setCenterX(Math.random() * 800); circle.setCenterY(Math.random() * 600); circle.setFill(new Color(Math.random(), Math.random(), Math.random(), .2)); circle.setEffect(new BoxBlur(10, 10, 3)); circle.setStroke(Color.WHITE); [setup binding…] [setup event listeners…] circles.add(circle); } 13
  • 14. Create the Circles List<Circle> circles = Streams.generate(() -> { final Circle circle = new Circle(150); circle.setCenterX(Math.random() * 800); circle.setCenterY(Math.random() * 600); circle.setFill(new Color(Math.random(), Math.random(), Math.random(), .2)); circle.setEffect(new BoxBlur(10, 10, 3)); circle.setStroke(Color.WHITE); [setup binding…] [setup event listeners…] return circle; }).limit(50).collect(Collectors.toList()); 14
  • 16. Setup Event Listeners circle.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { public void handle(MouseEvent t) { KeyValue collapse = new KeyValue(circle.radiusProperty(), 0); new Timeline(new KeyFrame(Duration.seconds(3), collapse)).play(); } }); 16
  • 17. Lambda-ized Event Listeners circle.addEventHandler(MouseEvent.MOUSE_CLICKED, e -> { KeyValue collapse = new KeyValue(circle.radiusProperty(), 0); new Timeline(new KeyFrame(Duration.seconds(3), collapse)).play(); }); 17
  • 18. Begin the Animation Timeline moveCircles = new Timeline(); for (Circle circle : circles) { KeyValue moveX = new KeyValue(circle.centerXProperty(), Math.random() * 800); KeyValue moveY = new KeyValue(circle.centerYProperty(), Math.random() * 600); moveCircles.getKeyFrames().add(new KeyFrame(Duration.seconds(40), moveX, moveY)); } moveCircles.play(); 18
  • 19. Lambda-ized Begin the Animation Timeline moveCircles = new Timeline(); circles.forEach(circle -> { KeyValue moveX = new KeyValue(circle.centerXProperty(), Math.random() * 800); KeyValue moveY = new KeyValue(circle.centerYProperty(), Math.random() * 600); moveCircles.getKeyFrames().add(new KeyFrame(Duration.seconds(40), moveX, moveY)); }); moveCircles.play(); 19
  • 20. Mary Had a Little Lambda Mary had a little lambda Whose fleece was white as snow And everywhere that Mary went Lambda was sure to go! https://github.com/steveonjava/MaryHadALittleLambda
  • 21. Generating Streams From a collection: > anyCollection.stream(); Known set of objects: > Stream.of("bananas", "oranges", "apples"); Numeric range: > IntStream.range(0, 50) Iteratively: > Stream.iterate(Color.RED, > c -> Color.hsb(c.getHue() + .1, c.getSaturation(), > c.getBrightness())); 21
  • 22. Let's Create Some Barn Animals! SpriteView tail = s.getAnimals().isEmpty() ? s : s.getAnimals().get(s.getAnimals().size() - 1); Stream.iterate(tail, SpriteView.Lamb::new) .substream(1, 8) .forEach(s.getAnimals()::add); 22
  • 23. 23
  • 24. Filtering Streams Predicate Expression > public interface Predicate<T> { > public boolean test(T t); > } Filter out minors > adults = attendees.filter(a -> a.getAge() >= 1.8) 24
  • 25. Rainbow-colored Lambs! s.getAnimals().stream() .filter(a -> a.getNumber() % 4 == 2) .forEach(a -> a.setColor(Color.YELLOW)); s.getAnimals().stream() .filter(a -> a.getNumber() % 4 == 3) .forEach(a -> a.setColor(Color.CYAN)); s.getAnimals().stream() .filter(a -> a.getNumber() % 4 == 0) .forEach(a -> a.setColor(Color.GREEN)); 25
  • 26. 26
  • 27. Filtering Collections Collection.removeIf > Removes all elements that match the predicate List.replaceAll > In-place filtering and replacement using an unary operator ObservableCollection.filtered > Returns a list filtered by a predicate this is also Observable 27
  • 28. Picky Eaters… Predicate<SpriteView> pure = a -> a.getColor() == null; mealsServed.set(mealsServed.get() + s.getAnimals().filtered(pure).size() ); s.getAnimals().removeIf(pure); 28
  • 29. 29
  • 30. Mapping Streams Applies a Map Function to each element: > Function<? super T, ? extends R> Result: List is the same size, but may be a different type. 30
  • 31. Single Map s.getAnimals().setAll(s.getAnimals() .stream() .map(sv -> new Eggs(sv.getFollowing()) .collect(Collectors.toList()) ); 31
  • 32. Or a Double Map! s.getAnimals().setAll(s.getAnimals() .stream() .map(SpriteView::getFollowing) .map(Eggs::new) .collect(Collectors.toList()) ); 32
  • 33. 33
  • 34. Flat Map Applies a One-to-Many Map Function to each element: > Function<? super T, ? extends Stream<? extends R>> And then flattens the result into a single stream. Result: The list may get longer and the type may be different. 34
  • 36. 36
  • 37. Reduce Reduces a list to a single element given: > Identity: T > Accumulator: BinaryOperator<T> Result: List of the same type, but only 1 element left. 37
  • 38. And the (formerly little) Fox ate them all! Double mealSize = shepherd.getAnimals() .stream() .map(SpriteView::getScaleX) .reduce(0.0, Double::sum); setScaleX(getScaleX() + mealSize * .2); setScaleY(getScaleY() + mealSize * .2); shepherd.getAnimals().clear(); 38
  • 39. 39
  • 40. Mary Had a Little Lambda Project > > Open-source project to demonstrate lambda features Visual representation of streams, filters, and maps https://github.com/steveonjava/MaryHadALittleLambda 40
  • 41. NightHacking Tour Stephen Chin tweet: @steveonjava blog: http://steveonjava.com Real Geeks Live Hacking nighthacking.com
  • 42. Graphics Image Credits > > > > > > Mary image by Terra-chan: http://www.rpgmakervx.net/index.php?showtopic=29404 Lamb image by Mack: http://www.rpgmakervx.net/index.php?showtopic=15704 Chicken, Church, Barn, and Coop image by LovelyBlue: http://l0velyblue.deviantart.com/art/Chicken-203764427 Fox image by PinedaVX: http://www.rpgmakervx.net/index.php?showtopic=9422 Nest image derived from Lokilech's Amselnest: http://commons.wikimedia.org/wiki/File:Amselnest_lokilech.jpg Background image by Victor Szalvay: http://www.flickr.com/photos/55502991@N00/172603855 42
  • 43. Safe Harbor Statement The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.