SlideShare ist ein Scribd-Unternehmen logo
1 von 75
Lambdas and Laughs 
Jim Bethancourt Houston JUG 
@jimbethancourt
Forward Looking Statement 
Ok, Not Really…
Topics Covered 
• Lambda Support 
• Lambda syntax 
• Interface enhancements 
• Convert inner class to 
Lambda 
• forEach & Streams 
• Method & Constructor 
References 
• Functional API
Download Links & IDE Support 
• Regular JDK download link 
• http://jdk8.java.net/download.html (for EAs) 
• Netbeans 
• IntelliJ 
• Eclipse
Maven Support 
<plugin> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-compiler-plugin</artifactId> 
<version>2.3.2</version> <!-- or higher – up to 3.1 now --> 
<configuration> 
<source>1.8</source> 
<target>1.8</target> 
</configuration> 
</plugin>
Lambdas 
A lambda expression is like a method: it provides 
a list of formal parameters and a body—an 
expression or block—expressed in terms of 
those parameters. 
Expressions: 
s -> s.length() 
(int x, int y) -> x+y 
() -> 42 
Assign lambda to functional interface: 
Runnable r1 = () -> 
System.out.println("My Runnable");
Lambdas 
Blocks: 
(x, y, z) -> { 
if (x==y) return x; 
else { 
int result = y; 
for (int i = 1; i < z; i++) 
result *= i; 
return result; 
}}
Typical Use Cases 
• Anonymous classes (GUI listeners) 
• Runnables / Callables 
• Comparator 
• Apply operation to a collection via foreach 
method 
• Chain operations on a collection with Stream API
MOAR !!! 
Monday 
• Programming with Lambda 
Expressions in Java [CON1770] 
11 AM Hilton Imperial A 
• GS Collections and Java 8: 
Functional, Fluent, Friendly, and 
Fun [CON5423] 
11 AM Hilton Imperial B 
• Under the Hood of Java 8 Parallel 
Streams with an Oracle Solaris 
Dtrace [BOF1937] 
9: 45 PM Moscone North 131 
Tuesday 
• Jump-Starting Lambda 
[TUT3371] 
10:30 AM Hilton Yosimite B/C 
• Lambda Under the 
Hood [CON4180] 
11 AM Hilton Imperial A 
• Lambda Q&A Panel [CON3374] 
1:30 PM Hilton Yosimite B/C
MOAR!!! 
Thursday 
• Lambda Programming Laboratory [HOL3373] 
2 PM Hilton Franciscan A/B 
• Lambda-izing JavaFX [CON3248] 
3:30 PM Hilton Plaza A
Effectively Final 
• For both lambda bodies and inner classes, local 
variables in the enclosing context can only be 
referenced if they are final or effectively final. 
• A variable is effectively final if its value is not 
reassigned after its initialization. 
• No longer need to litter code with final keyword
Interface Defender Methods 
• Interface methods with bodies 
• default keyword 
• More graceful API evolution 
• Interfaces have no state 
• Static methods not inherited 
• Can reference abstract method 
• Called “Extended Interfaces” if no abstract methods 
present
Super! 
• Extended Interfaces can 
extend other extended 
interfaces 
• Methods can be 
overridden 
• Can decorate parent 
definitions via super 
interface I1 { default void 
method1() {//do stuff}} 
interface I2 extends I1{ 
default void method1() { 
super.method1(); 
//do new stuff 
}}
Specify the Parent Interface 
interface D1 { default void meth1() {//do stuff}} 
interface D2 extends D1{ void default meth1() { 
super.method1(); //do new stuff}} 
interface D3 extends D1{ void default meth1() { 
super.method1(); //do new stuff}} 
interface D4 extends D2, D3{ 
void default meth1() { 
D2.super.method1(); //do new stuff}}
Convert Anonymous Class to Lambda 
from http://learnjavafx.typepad.com/weblog/2013/02/mary-had-a-little-%CE%BB.html 
// Anonymous inner class for event handling 
.onAction(new EventHandler<ActionEvent>() { 
@Override 
public void handle(ActionEvent e) { 
anim.playFromStart(); 
} 
})
Convert Anonymous Class to Lambda 
• .onAction((ActionEvent) -> { 
anim.playFromStart(); } }) 
• .onAction((e) -> {anim.playFromStart();})
Convert Anonymous Class to Lambda 
• .onAction((ActionEvent) -> { 
anim.playFromStart(); } }) 
• .onAction((e) -> {anim.playFromStart();}) 
• .onAction(e -> { anim.playFromStart(); }) 
• .onAction(e -> anim.playFromStart();)
MOAR!!! 
• Transforming Code to Java 8 [CON1772] 
Thursday 2:30 Hilton Imperial B
forEach 
• forEach() - available on Iterator & Map interfaces and their 
implementations 
• Allows for internal control of iteration of elements for 
possible parallel operation 
List<String> names = 
Arrays.asList(“Bill", “Ed", “Al"); 
names.forEach(e -> { System.out.println(e); }); 
But be careful!!!
MOAR!!! 
• GS Collections and Java 8: Functional, Fluent, 
Friendly, and Fun [CON5423] 
Monday 11 AM Hilton Imperial B 
• Autumn Collections: From Iterable to Lambdas, 
Streams, and Collectors [TUT3472] 
Tuesday 8:30 AM Hilton Yosemite A 
• New Tricks for Old Dogs: Collections in Java 8 
[CON6309] Thursday 4 PM Hilton Imperial A
java.util.stream 
• Classes to support functional-style operations 
on streams of values 
• Stream<T> - A sequence of elements 
supporting sequential and parallel bulk ops
java.util.stream 
• Stream opened by calling 
– Collection.stream() 
– Collection.parallelStream() 
List<String> names = 
Arrays.asList("Bill", “Ed", “Al"); 
out(names.stream().filter(e -> e.length() >= 4 ) 
.findFirst().get()); 
Returns “Bill”
java.util.stream 
• All other interfaces in stream package 
accessible through Stream interface 
• Collector<T,R> - A (possibly parallel) reduction 
operation. 
• FlatMapper<T,U> - Maps element of type T to 
zero or more elements of type U.
MOAR!!! 
• Journey’s End: Collection and Reduction in the 
Stream API [TUT3836] 
Monday 8:30 AM Hilton Yosemite A 
• Programming with Streams in Java 8 [CON1771] 
Monday 4 PM Hilton Imperial A 
• Parallel Streams Workshop [CON3372] 
Wednesday 10 AM Hilton Yosemite A 
• Loads more!!!
java.util 
• Spliterator<T> provides traversal operations 
• Optional<T> 
– Returned by Stream’s aggregate methods 
find*(), reduce(), min(), max() 
– Call get() to get the value it’s holding
Method & Constructor References 
• A method reference is used to refer to a (static 
or instance) method without invoking it 
• A constructor reference is similarly used to 
refer to a constructor without creating a new 
instance of the named class or array type. 
• Specified with the :: (double colon) operator
Method & Constructor References 
• Provide a way to refer to a method / constructor without 
invoking it 
• Examples: 
System::getProperty 
"abc"::length 
String::length 
super::toString 
ArrayList::new 
int[]::new
Convert call to Method Reference 
public class Test { 
static void foo(){} 
static { 
new Runnable() { 
@Override 
public void run() { 
Test.foo(); 
} 
}.run(); 
}}
Convert call to Method Reference 
public class Test { 
static void foo(){} 
static { 
((Runnable) () -> Test.foo()).run(); 
} 
}
Convert call to Method Reference 
public class Test { 
static void foo(){} 
static { 
((Runnable) Test::foo()).run(); 
} 
}
Use a Method Reference 
This 
bttnExit.setOnAction( 
(actionEvent) -> { 
try { 
stop(); 
} catch (Exception e) { 
// TODO: add error handling 
} }); 
Can be 
bttnExit.setOnAction( 
this::onExitButtonClick); 
... 
void onExitButtonClick() { 
try { 
stop(); 
} catch (Exception e) { 
// TODO: add error handling 
} 
}
Use a Constructor Reference 
interface Factory<T> { T make(); } 
Factory<List<String>> f1 = 
ArrayList::<String>new; 
• Every time make() is invoked, it will return a 
new ArrayList<String>
How many times have 
you heard
Whatever! 
Method assigned to privileged interface: 
public class Main { 
public static class NotAutoCloseable { 
public void close() throws Exception { 
System.out.println("CLOSE"); } } 
public static void main(String... args) throws Exception { 
NotAutoCloseable nac = new NotAutoCloseable(); 
try (AutoCloseable ac = nac::close) {}}}
Functional Interface 
• Has just one abstract 
method. (Can have other 
methods with bodies) 
• Represents a functional 
contract. 
• The @FunctionalInterface 
annotation helps ensure the 
Functional Interface 
contract is honored
Functional Interface 
• What happens when you have more than one 
abstract method & use @FunctionalInterface?
java.util.function 
• Functional interfaces provide target types for lambda 
expressions and method references 
• Consumer<T> 
• Function<T,R> 
• Supplier<T> 
• Predicate<T> 
• Unary/BinaryOperator<T> 
• Bi(Consumer/Function/Predicate)<T,U(,R)>
public static <X, Y> void processElements( 
Iterable<X> source, Predicate<X> tester, 
Function <X, Y> mapper, Consumer<Y> block) { 
for (X p : source) { 
if (tester.test(p)) { 
Y data = mapper.apply(p); 
block.accept(data); 
} } } 
from http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html
MOAR!!! 
• Thinking in Functional Style [CON1767] 
Monday 2:30 PM Hilton Yosemite B/C 
• Twins: FP and OOP [CON2159] 
Monday 2:30 PM Hilton Continental 7/8/9 
• Loads more (insanely huge list for functional 
programming)
New Java 8 Feature Overview 
• http://openjdk.java.net/projects/jdk8/features 
• http://java.dzone.com/articles/java-%E2%80%93- 
far-sight-look-jdk-8 
Java 8 Maven Support 
• http://illegalargumentexception.blogspot.com/20 
12/08/java-lambda-support-in-java-8.html
Lambda JSR 
• http://jcp.org/en/jsr/detail?id=335 
Articles on Lambdas 
• http://www.oraclejavamagazine-digital.com/javamagazine/20121112?pg=35#pg35 
• http://www.angelikalanger.com/Conferences/Slides/jf12_LambdasInJava8-1.pdf 
• http://datumedge.blogspot.com/2012/06/java-8-lambdas.html 
• http://www.infoq.com/articles/java-8-vs-scala 
Presentations on Lambdas: 
• http://www.slideshare.net/ramonypp/java-8-project-lambda 
• http://www.slideshare.net/garthbrown/lambda-functions-in-java-8 
• http://www.angelikalanger.com/Conferences/Slides/jf12_LambdasInJava8-1.pdf 
Lambda implementation mechanics: 
• http://cr.openjdk.java.net/~briangoetz/lambda/lambda-translation.html
Typical lambda use cases: 
• http://learnjavafx.typepad.com/weblog/2013/02/mary-had-a-little-%CE%BB.html 
• http://blueskyworkshop.com/topics/Java-Pages/lambda-expression-basics/ 
• http://java.dzone.com/articles/devoxx-2012-java-8-lambda-and 
Defender method paper: 
• http://cr.openjdk.java.net/~briangoetz/lambda/Defender%20Methods%20v4.pdf 
Method references (:: operator) 
• http://earthly-powers.blogspot.com/2012/07/java-8-lambda-and-method-references.html 
• http://doanduyhai.wordpress.com/2012/07/14/java-8-lambda-in-details-part-iii-method-and-constructor-referencing/ 
• http://www.beyondjava.net/blog/are-java-8-method-references-going-to-be-more-important-than-lambdas/ 
• http://www.lambdafaq.org/what-are-constructor-references/ 
Stream API: 
• http://cr.openjdk.java.net/~briangoetz/lambda/sotc3.html 
• http://aruld.info/java-8-this-aint-your-grandpas-java/ 
• http://java.dzone.com/articles/exciting-ideas-java-8-streams 
Sophisticated Lambda use case allowing for avoiding NPEs using Monads: 
• http://java.dzone.com/articles/no-more-excuses-use-null 
Functional programming in Java 
• http://code.google.com/p/functionaljava/ 
• http://shop.oreilly.com/product/0636920021667.do 
• http://apocalisp.wordpress.com/2008/06/18/parallel-strategies-and-the-callable-monad/
Thank you!

Weitere ähnliche Inhalte

Was ist angesagt?

New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8Martin Toshev
 
java 8 new features
java 8 new features java 8 new features
java 8 new features Rohit Verma
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java langer4711
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Ganesh Samarthyam
 
Java SE 8 - New Features
Java SE 8 - New FeaturesJava SE 8 - New Features
Java SE 8 - New FeaturesNaveen Hegde
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIGanesh Samarthyam
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressionsLogan Chien
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in JavaErhan Bagdemir
 
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
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhHarmeet Singh(Taara)
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project LambdaRahman USTA
 
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)Harmeet Singh(Taara)
 

Was ist angesagt? (20)

New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
 
Java SE 8 - New Features
Java SE 8 - New FeaturesJava SE 8 - New Features
Java SE 8 - New Features
 
Java concurrency questions and answers
Java concurrency questions and answers Java concurrency questions and answers
Java concurrency questions and answers
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
 
Java 8 new features
Java 8 new featuresJava 8 new features
Java 8 new features
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
Streams in Java 8
Streams in Java 8Streams in Java 8
Streams in Java 8
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
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
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singh
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project Lambda
 
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
 

Andere mochten auch

Future Of The Web, Now
Future Of The Web, NowFuture Of The Web, Now
Future Of The Web, NowDerek Hammer
 
Atlassian Bamboo Feature Overview
Atlassian Bamboo Feature OverviewAtlassian Bamboo Feature Overview
Atlassian Bamboo Feature OverviewJim Bethancourt
 
Continuous integration using atlassian bamboo
Continuous integration using atlassian bambooContinuous integration using atlassian bamboo
Continuous integration using atlassian bambooAlexander Masalov
 
Continuous Deployment with Bamboo and Deployit
Continuous Deployment with Bamboo and DeployitContinuous Deployment with Bamboo and Deployit
Continuous Deployment with Bamboo and DeployitXebiaLabs
 

Andere mochten auch (7)

Java Performance Tweaks
Java Performance TweaksJava Performance Tweaks
Java Performance Tweaks
 
Refactor to the Limit!
Refactor to the Limit!Refactor to the Limit!
Refactor to the Limit!
 
Active Model
Active ModelActive Model
Active Model
 
Future Of The Web, Now
Future Of The Web, NowFuture Of The Web, Now
Future Of The Web, Now
 
Atlassian Bamboo Feature Overview
Atlassian Bamboo Feature OverviewAtlassian Bamboo Feature Overview
Atlassian Bamboo Feature Overview
 
Continuous integration using atlassian bamboo
Continuous integration using atlassian bambooContinuous integration using atlassian bamboo
Continuous integration using atlassian bamboo
 
Continuous Deployment with Bamboo and Deployit
Continuous Deployment with Bamboo and DeployitContinuous Deployment with Bamboo and Deployit
Continuous Deployment with Bamboo and Deployit
 

Ähnlich wie Lambdas and Laughs

New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 itiAhmed mar3y
 
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
 
Lambdas & Streams
Lambdas & StreamsLambdas & Streams
Lambdas & StreamsC4Media
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeLambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeIan Robertson
 
Lambdas : Beyond The Basics
Lambdas : Beyond The BasicsLambdas : Beyond The Basics
Lambdas : Beyond The BasicsSimon Ritter
 
Charles Sharp: Java 8 Streams
Charles Sharp: Java 8 StreamsCharles Sharp: Java 8 Streams
Charles Sharp: Java 8 Streamsjessitron
 
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
 
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...jaxLondonConference
 
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesAutomatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesRaffi Khatchadourian
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()daewon jeong
 
A brief tour of modern Java
A brief tour of modern JavaA brief tour of modern Java
A brief tour of modern JavaSina Madani
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxBruceLee275640
 
The Road to Lambda - Mike Duigou
The Road to Lambda - Mike DuigouThe Road to Lambda - Mike Duigou
The Road to Lambda - Mike Duigoujaxconf
 
Functional Programming With Lambdas and Streams in JDK8
 Functional Programming With Lambdas and Streams in JDK8 Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8IndicThreads
 

Ähnlich wie Lambdas and Laughs (20)

Java gets a closure
Java gets a closureJava gets a closure
Java gets a closure
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
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
 
Lambdas & Streams
Lambdas & StreamsLambdas & Streams
Lambdas & Streams
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeLambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive Code
 
Java 8 Intro - Core Features
Java 8 Intro - Core FeaturesJava 8 Intro - Core Features
Java 8 Intro - Core Features
 
Lambdas : Beyond The Basics
Lambdas : Beyond The BasicsLambdas : Beyond The Basics
Lambdas : Beyond The Basics
 
Charles Sharp: Java 8 Streams
Charles Sharp: Java 8 StreamsCharles Sharp: Java 8 Streams
Charles Sharp: Java 8 Streams
 
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
 
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
Project Lambda: Functional Programming Constructs in Java - Simon Ritter (Ora...
 
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesAutomatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to Interfaces
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()
 
Java8.part2
Java8.part2Java8.part2
Java8.part2
 
A brief tour of modern Java
A brief tour of modern JavaA brief tour of modern Java
A brief tour of modern Java
 
Java 8
Java 8Java 8
Java 8
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptx
 
The Road to Lambda - Mike Duigou
The Road to Lambda - Mike DuigouThe Road to Lambda - Mike Duigou
The Road to Lambda - Mike Duigou
 
Functional Programming With Lambdas and Streams in JDK8
 Functional Programming With Lambdas and Streams in JDK8 Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8
 
Java 8
Java 8Java 8
Java 8
 

Mehr von Jim Bethancourt

Functional Programming in Java
Functional Programming in JavaFunctional Programming in Java
Functional Programming in JavaJim Bethancourt
 
Migrating to Maven 2 Demystified
Migrating to Maven 2 DemystifiedMigrating to Maven 2 Demystified
Migrating to Maven 2 DemystifiedJim Bethancourt
 
Hearthstone To The Limit
Hearthstone To The LimitHearthstone To The Limit
Hearthstone To The LimitJim Bethancourt
 
Recognize, assess, reduce, and manage technical debt
Recognize, assess, reduce, and manage technical debtRecognize, assess, reduce, and manage technical debt
Recognize, assess, reduce, and manage technical debtJim Bethancourt
 

Mehr von Jim Bethancourt (9)

JavaOne 2011 Recap
JavaOne 2011 RecapJavaOne 2011 Recap
JavaOne 2011 Recap
 
Ready, Set, Refactor
Ready, Set, RefactorReady, Set, Refactor
Ready, Set, Refactor
 
Introduction to CDI
Introduction to CDIIntroduction to CDI
Introduction to CDI
 
Functional Programming in Java
Functional Programming in JavaFunctional Programming in Java
Functional Programming in Java
 
Young Java Champions
Young Java ChampionsYoung Java Champions
Young Java Champions
 
Migrating to Maven 2 Demystified
Migrating to Maven 2 DemystifiedMigrating to Maven 2 Demystified
Migrating to Maven 2 Demystified
 
User Group Leader Lunch
User Group Leader LunchUser Group Leader Lunch
User Group Leader Lunch
 
Hearthstone To The Limit
Hearthstone To The LimitHearthstone To The Limit
Hearthstone To The Limit
 
Recognize, assess, reduce, and manage technical debt
Recognize, assess, reduce, and manage technical debtRecognize, assess, reduce, and manage technical debt
Recognize, assess, reduce, and manage technical debt
 

Kürzlich hochgeladen

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
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
 
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
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
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.
 
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
 
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
 
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
 
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
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
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
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
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
 
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
 
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
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 

Kürzlich hochgeladen (20)

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
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 ...
 
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
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
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 ...
 
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
 
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
 
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-...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
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
 
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
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
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
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
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
 
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 🔝✔️✔️
 
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
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 

Lambdas and Laughs

  • 1. Lambdas and Laughs Jim Bethancourt Houston JUG @jimbethancourt
  • 2. Forward Looking Statement Ok, Not Really…
  • 3. Topics Covered • Lambda Support • Lambda syntax • Interface enhancements • Convert inner class to Lambda • forEach & Streams • Method & Constructor References • Functional API
  • 4. Download Links & IDE Support • Regular JDK download link • http://jdk8.java.net/download.html (for EAs) • Netbeans • IntelliJ • Eclipse
  • 5. Maven Support <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <!-- or higher – up to 3.1 now --> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin>
  • 6.
  • 7.
  • 8. Lambdas A lambda expression is like a method: it provides a list of formal parameters and a body—an expression or block—expressed in terms of those parameters. Expressions: s -> s.length() (int x, int y) -> x+y () -> 42 Assign lambda to functional interface: Runnable r1 = () -> System.out.println("My Runnable");
  • 9.
  • 10. Lambdas Blocks: (x, y, z) -> { if (x==y) return x; else { int result = y; for (int i = 1; i < z; i++) result *= i; return result; }}
  • 11. Typical Use Cases • Anonymous classes (GUI listeners) • Runnables / Callables • Comparator • Apply operation to a collection via foreach method • Chain operations on a collection with Stream API
  • 12.
  • 13.
  • 14. MOAR !!! Monday • Programming with Lambda Expressions in Java [CON1770] 11 AM Hilton Imperial A • GS Collections and Java 8: Functional, Fluent, Friendly, and Fun [CON5423] 11 AM Hilton Imperial B • Under the Hood of Java 8 Parallel Streams with an Oracle Solaris Dtrace [BOF1937] 9: 45 PM Moscone North 131 Tuesday • Jump-Starting Lambda [TUT3371] 10:30 AM Hilton Yosimite B/C • Lambda Under the Hood [CON4180] 11 AM Hilton Imperial A • Lambda Q&A Panel [CON3374] 1:30 PM Hilton Yosimite B/C
  • 15. MOAR!!! Thursday • Lambda Programming Laboratory [HOL3373] 2 PM Hilton Franciscan A/B • Lambda-izing JavaFX [CON3248] 3:30 PM Hilton Plaza A
  • 16.
  • 17. Effectively Final • For both lambda bodies and inner classes, local variables in the enclosing context can only be referenced if they are final or effectively final. • A variable is effectively final if its value is not reassigned after its initialization. • No longer need to litter code with final keyword
  • 18.
  • 19. Interface Defender Methods • Interface methods with bodies • default keyword • More graceful API evolution • Interfaces have no state • Static methods not inherited • Can reference abstract method • Called “Extended Interfaces” if no abstract methods present
  • 20.
  • 21. Super! • Extended Interfaces can extend other extended interfaces • Methods can be overridden • Can decorate parent definitions via super interface I1 { default void method1() {//do stuff}} interface I2 extends I1{ default void method1() { super.method1(); //do new stuff }}
  • 22.
  • 23. Specify the Parent Interface interface D1 { default void meth1() {//do stuff}} interface D2 extends D1{ void default meth1() { super.method1(); //do new stuff}} interface D3 extends D1{ void default meth1() { super.method1(); //do new stuff}} interface D4 extends D2, D3{ void default meth1() { D2.super.method1(); //do new stuff}}
  • 24.
  • 25. Convert Anonymous Class to Lambda from http://learnjavafx.typepad.com/weblog/2013/02/mary-had-a-little-%CE%BB.html // Anonymous inner class for event handling .onAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { anim.playFromStart(); } })
  • 26.
  • 27. Convert Anonymous Class to Lambda • .onAction((ActionEvent) -> { anim.playFromStart(); } }) • .onAction((e) -> {anim.playFromStart();})
  • 28.
  • 29. Convert Anonymous Class to Lambda • .onAction((ActionEvent) -> { anim.playFromStart(); } }) • .onAction((e) -> {anim.playFromStart();}) • .onAction(e -> { anim.playFromStart(); }) • .onAction(e -> anim.playFromStart();)
  • 30.
  • 31. MOAR!!! • Transforming Code to Java 8 [CON1772] Thursday 2:30 Hilton Imperial B
  • 32.
  • 33. forEach • forEach() - available on Iterator & Map interfaces and their implementations • Allows for internal control of iteration of elements for possible parallel operation List<String> names = Arrays.asList(“Bill", “Ed", “Al"); names.forEach(e -> { System.out.println(e); }); But be careful!!!
  • 34.
  • 35.
  • 36.
  • 37. MOAR!!! • GS Collections and Java 8: Functional, Fluent, Friendly, and Fun [CON5423] Monday 11 AM Hilton Imperial B • Autumn Collections: From Iterable to Lambdas, Streams, and Collectors [TUT3472] Tuesday 8:30 AM Hilton Yosemite A • New Tricks for Old Dogs: Collections in Java 8 [CON6309] Thursday 4 PM Hilton Imperial A
  • 38.
  • 39. java.util.stream • Classes to support functional-style operations on streams of values • Stream<T> - A sequence of elements supporting sequential and parallel bulk ops
  • 40. java.util.stream • Stream opened by calling – Collection.stream() – Collection.parallelStream() List<String> names = Arrays.asList("Bill", “Ed", “Al"); out(names.stream().filter(e -> e.length() >= 4 ) .findFirst().get()); Returns “Bill”
  • 41. java.util.stream • All other interfaces in stream package accessible through Stream interface • Collector<T,R> - A (possibly parallel) reduction operation. • FlatMapper<T,U> - Maps element of type T to zero or more elements of type U.
  • 42.
  • 43.
  • 44. MOAR!!! • Journey’s End: Collection and Reduction in the Stream API [TUT3836] Monday 8:30 AM Hilton Yosemite A • Programming with Streams in Java 8 [CON1771] Monday 4 PM Hilton Imperial A • Parallel Streams Workshop [CON3372] Wednesday 10 AM Hilton Yosemite A • Loads more!!!
  • 45.
  • 46. java.util • Spliterator<T> provides traversal operations • Optional<T> – Returned by Stream’s aggregate methods find*(), reduce(), min(), max() – Call get() to get the value it’s holding
  • 47.
  • 48. Method & Constructor References • A method reference is used to refer to a (static or instance) method without invoking it • A constructor reference is similarly used to refer to a constructor without creating a new instance of the named class or array type. • Specified with the :: (double colon) operator
  • 49. Method & Constructor References • Provide a way to refer to a method / constructor without invoking it • Examples: System::getProperty "abc"::length String::length super::toString ArrayList::new int[]::new
  • 50.
  • 51. Convert call to Method Reference public class Test { static void foo(){} static { new Runnable() { @Override public void run() { Test.foo(); } }.run(); }}
  • 52. Convert call to Method Reference public class Test { static void foo(){} static { ((Runnable) () -> Test.foo()).run(); } }
  • 53. Convert call to Method Reference public class Test { static void foo(){} static { ((Runnable) Test::foo()).run(); } }
  • 54.
  • 55. Use a Method Reference This bttnExit.setOnAction( (actionEvent) -> { try { stop(); } catch (Exception e) { // TODO: add error handling } }); Can be bttnExit.setOnAction( this::onExitButtonClick); ... void onExitButtonClick() { try { stop(); } catch (Exception e) { // TODO: add error handling } }
  • 56. Use a Constructor Reference interface Factory<T> { T make(); } Factory<List<String>> f1 = ArrayList::<String>new; • Every time make() is invoked, it will return a new ArrayList<String>
  • 57. How many times have you heard
  • 58.
  • 59. Whatever! Method assigned to privileged interface: public class Main { public static class NotAutoCloseable { public void close() throws Exception { System.out.println("CLOSE"); } } public static void main(String... args) throws Exception { NotAutoCloseable nac = new NotAutoCloseable(); try (AutoCloseable ac = nac::close) {}}}
  • 60.
  • 61.
  • 62. Functional Interface • Has just one abstract method. (Can have other methods with bodies) • Represents a functional contract. • The @FunctionalInterface annotation helps ensure the Functional Interface contract is honored
  • 63. Functional Interface • What happens when you have more than one abstract method & use @FunctionalInterface?
  • 64.
  • 65.
  • 66. java.util.function • Functional interfaces provide target types for lambda expressions and method references • Consumer<T> • Function<T,R> • Supplier<T> • Predicate<T> • Unary/BinaryOperator<T> • Bi(Consumer/Function/Predicate)<T,U(,R)>
  • 67.
  • 68. public static <X, Y> void processElements( Iterable<X> source, Predicate<X> tester, Function <X, Y> mapper, Consumer<Y> block) { for (X p : source) { if (tester.test(p)) { Y data = mapper.apply(p); block.accept(data); } } } from http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html
  • 69.
  • 70. MOAR!!! • Thinking in Functional Style [CON1767] Monday 2:30 PM Hilton Yosemite B/C • Twins: FP and OOP [CON2159] Monday 2:30 PM Hilton Continental 7/8/9 • Loads more (insanely huge list for functional programming)
  • 71.
  • 72. New Java 8 Feature Overview • http://openjdk.java.net/projects/jdk8/features • http://java.dzone.com/articles/java-%E2%80%93- far-sight-look-jdk-8 Java 8 Maven Support • http://illegalargumentexception.blogspot.com/20 12/08/java-lambda-support-in-java-8.html
  • 73. Lambda JSR • http://jcp.org/en/jsr/detail?id=335 Articles on Lambdas • http://www.oraclejavamagazine-digital.com/javamagazine/20121112?pg=35#pg35 • http://www.angelikalanger.com/Conferences/Slides/jf12_LambdasInJava8-1.pdf • http://datumedge.blogspot.com/2012/06/java-8-lambdas.html • http://www.infoq.com/articles/java-8-vs-scala Presentations on Lambdas: • http://www.slideshare.net/ramonypp/java-8-project-lambda • http://www.slideshare.net/garthbrown/lambda-functions-in-java-8 • http://www.angelikalanger.com/Conferences/Slides/jf12_LambdasInJava8-1.pdf Lambda implementation mechanics: • http://cr.openjdk.java.net/~briangoetz/lambda/lambda-translation.html
  • 74. Typical lambda use cases: • http://learnjavafx.typepad.com/weblog/2013/02/mary-had-a-little-%CE%BB.html • http://blueskyworkshop.com/topics/Java-Pages/lambda-expression-basics/ • http://java.dzone.com/articles/devoxx-2012-java-8-lambda-and Defender method paper: • http://cr.openjdk.java.net/~briangoetz/lambda/Defender%20Methods%20v4.pdf Method references (:: operator) • http://earthly-powers.blogspot.com/2012/07/java-8-lambda-and-method-references.html • http://doanduyhai.wordpress.com/2012/07/14/java-8-lambda-in-details-part-iii-method-and-constructor-referencing/ • http://www.beyondjava.net/blog/are-java-8-method-references-going-to-be-more-important-than-lambdas/ • http://www.lambdafaq.org/what-are-constructor-references/ Stream API: • http://cr.openjdk.java.net/~briangoetz/lambda/sotc3.html • http://aruld.info/java-8-this-aint-your-grandpas-java/ • http://java.dzone.com/articles/exciting-ideas-java-8-streams Sophisticated Lambda use case allowing for avoiding NPEs using Monads: • http://java.dzone.com/articles/no-more-excuses-use-null Functional programming in Java • http://code.google.com/p/functionaljava/ • http://shop.oreilly.com/product/0636920021667.do • http://apocalisp.wordpress.com/2008/06/18/parallel-strategies-and-the-callable-monad/

Hinweis der Redaktion

  1. 5 minute version at the Ignite Talk – Tuesday 7 – 9 PM Hilton Imperial A 15% discount on the next J1 conference if you go to 16 or more sessions
  2. Don’t get too creative with blocks, or you’ll defeat the purpose of lambdas. We’ll explore alternative solutions later using method references.
  3. When you see a slide that says MOAR! I want you to yell MOAR!!! Let’s try this!!! (Go back one slide and flip to this slide again) Test soon!!!
  4. Effectively final allows you to read code faster
  5. We wrote all this code in red, when all we really wanted to do was have an animation play
  6. Bullet point 1 - The lambda type is inferred by the compiler as EventHandler<ActionEvent> because the onAction() method takes an object of type EventHandler<ActionEvent>.  Bullet point 2 - The parameter in this lambda expression must be an ActionEvent, because that is the type specified by the handle() method of the EventHandler interface.
  7. Bullet point 3 - When a lambda expression has a single parameter and its type is inferred, the parentheses are not required Bullet point 4 - Because the block of code in our lambda expression contains only one statement, we can simplify it even further by removing the curly braces
  8. Trivia: Who knows who Bill, Ed and Al are? If you don’t know, I’ll tell you later…
  9. Bill, Ed and Al are Bill Coleman, Ed Scott, and Alfred Chuang, the founders of… BEA!!!
  10. Collector<T,R> - A (possibly parallel) reduction operation that folds input elements into a mutable result container. FlatMapper<T,U> - An operation that maps an element of type T to zero or more elements of type U.
  11. Uh, sorry kid, not quite the streams we were talking about…
  12. Spliterator<T> - A provider of element traversal operations for a possibly-parallel computation. Optional<T> - A container object which may or may not contain a non-null value, key enabler of functional programming
  13. A method reference is used to refer to a (static or instance) method without invoking it A constructor reference is similarly used to refer to a constructor without creating a new instance of the named class or array type.
  14. A static method (ClassName::methName) An instance method of a particular object (instanceRef::methName) A super method of a particular object (super::methName) An instance method of an arbitrary object of a particular type (ClassName::methName) A class constructor reference (ClassName::new) An array constructor reference (TypeName[]::new)
  15. Lambda blocks can be avoided by using method references, and you get a method out of it
  16. Ouch!
  17. Poor Bad Luck Brian… Really, trying to write Java in a functional style before lambdas looked hideous
  18. Consumer<T> - Action to be performed on an object. Function<T,R> - transform a type T to a return type R. Supplier<T> - A supplier of objects (e.g. factory). Predicate<T> - Determines if the input object matches some criteria. Unary/BinaryOperator<T> - An operation upon a single / two operand(s) yielding a result. Bi(Consumer/Function/Predicate)<T,U(,R)> - Accepts two input arguments, yields result (R) if specified