SlideShare a Scribd company logo
© Henri Tremblay 2015
Henri Tremblay
Senior Software Engineer
Terracotta, a Software AG company
Learn Java 8: Lambdas and Functional
Programming
@henri_tremblay
2
Henri Tremblay
3
Henri Tremblay
4
Henri Tremblay
• More or less made possible class mocking and proxying
• Coined the term “partial mocking”
5
Henri Tremblay
• More or less made possible class mocking and proxying
• Coined the term “partial mocking”
6
7
Java < 8
8
Live Coding
9
Questions
10
Java 5
(2004)
11
JAVA 5 GAVE THE GENERIC
TYPES TO THE WORLD
(and also annotations, concurrent collections, enum types, for
each, static imports and so on and so on)
12
Type witness
Having
<T> T anyObject()
you can force the type with
MyClass.<List<String>> anyObject()
because
(List<String>) MyClass.anyObject()
gives a warning
13
Java 6
(2006, last from Sun)
14
JAVA 6 BROUGHT... PRETTY
MUCH NOTHING
(a bunch of performance improvements under the hood, better xml
parsing and the first scripting api)
15
Java 7
(2011, first from Oracle)
16
JAVA 7 BROUGHT A LOT OF
SYNTACTIC SUGAR
(plus invokeDynamic, ForkJoin, better file IO)
17
Switch for strings
switch(s) {
case "hello":
return "world";
case "bonjour":
return "le monde";
}
18
Diamond operator
List<String> list = new ArrayList<>();
19
Binary integer literals and underscores
int i = 0b1110001111;
int i = 1_000_000;
20
Multiple catches
try {
// ... do stuff
}
catch (IOException | SerializationException e) {
log.error("My error", e);
}
Instead of
try {
// ... do stuff
} catch (IOException e) {
log.error("My error", e);
} catch (SerializationException e) {
log.error("My error", e);
}
21
Auto Closeable
Before
InputStream in = new FileInputStream("allo.txt");
try {
// … do stuff
} finally {
try { in.close(); } catch(IOException e) {}
}
After
try(InputStream in = new FileInputStream("allo.txt")) {
// … do stuff
}
22
File IO API
List<String> lines =
Files.readAllLines(
Paths.get("path", "to", "my", "file.txt"));
// also: file watcher, symbolic links, file locks,
// copy… Look in java.nio.file
23
Java 8
(2014)
24
JAVA 8: LAMBDA!
(and also a new date API, default methods, metaspace, Nashorn,
JavaFX and CompletableFuture)
26
Date / Time API
Core ideas:
Immutable
A time is a time, a date is a date. Not always both (like java.util.Date)
Not everyone uses the same calendar (the same Chronology)
LocalDate, LocalTime, LocalDateTime  Local. No time zone
OffsetDateTime, OffsetTime  Time with an offset from
Greenwich
ZonedDateTime  LocalDateTime with a time zone
Duration, Period  Time span
Instant  Timestamp
Formatting  Easy and thread-safe formatting
27
Date / Time API (example)
LocalDateTime now = LocalDateTime.now();
String thatSpecialDay = now
.withDayOfMonth(1)
.atZone(ZoneId.of("Europe/Paris"))
.plus(Duration.ofDays(5))
.format(DateTimeFormatter.ISO_ZONED_DATE_TIME);
System.out.println(thatSpecialDay);
Output
2016-09-06T17:45:22.488+01:00[Europe/Paris]
28
29
Lambda: 11th letter of the Greek alphabet
30
(also written as λ-calculus) is a formal system in
mathematical logic for expressing computation based
on function abstraction and application using variable
binding and substitution. It is a universal model of
computation that can be used to simulate any single-
taped Turing machine and was first introduced by
mathematician Alonzo Church in the 1930s as part of
an investigation into the foundations of mathematics.
Lambda calculus
31
This is a function:
This is a lambda:
Lambda calculus
32
c = sqrt(add(pow(a, 2), pow(b, 2)))
Functional programming
33
45
The End
46
Who has learned
something today?
?
47
Brian Goetz – State of the lambda
http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-
final.html
http://cr.openjdk.java.net/~briangoetz/lambda/lambda-
translation.html
Ninja Squad – Lambda Kata
https://github.com/Ninja-Squad/ninjackaton-lambda
Maurice Naftalin’s lambda facts and books
http://www.lambdafaq.org/
Mastering Lamdbas: Java Programming in a Multicore World
Links
48
Questions? http://montreal-jug.org
?
http://easymock.org
http://objenesis.org
http:/ehcache.org
Henri Tremblay
http://blog.tremblay.pro
@henri_tremblay

More Related Content

PDF
Clojure, Plain and Simple
PDF
Clojure made-simple - John Stevenson
PPTX
Small Lambda Talk @Booster2015
PPT
Intro to Java for C++ Developers
PDF
JDK8 Functional API
PPTX
Kotlin - A very quick introduction
PDF
Javascript Performance
PPTX
Clojure, Plain and Simple
Clojure made-simple - John Stevenson
Small Lambda Talk @Booster2015
Intro to Java for C++ Developers
JDK8 Functional API
Kotlin - A very quick introduction
Javascript Performance

What's hot (20)

PDF
Xanadu - Java Chapter Meeting
PDF
Lisp for Python Programmers
PPT
Future Programming Language
PDF
Wait for your fortune without Blocking!
PPTX
Whats New in Java 8
KEY
Incremental Development with Lisp: Building a Game and a Website
PPTX
DevNexus 2020: Discover Modern Java
PPTX
01 Java Language And OOP Part I LAB
ODP
Java8
KEY
LISP: How I Learned To Stop Worrying And Love Parantheses
PPTX
What is String in Java?
PPT
Python by ganesh kavhar
PPTX
06 Java Language And OOP Part VI
ODP
From Java 6 to Java 7 reference
ODP
Quick introduction to Java Garbage Collector (JVM GC)
PPT
Java intro
PPT
RIBBUN SOFTWARE
PPT
Java01
ODP
Best practices in Java
PDF
Why GC is eating all my CPU?
Xanadu - Java Chapter Meeting
Lisp for Python Programmers
Future Programming Language
Wait for your fortune without Blocking!
Whats New in Java 8
Incremental Development with Lisp: Building a Game and a Website
DevNexus 2020: Discover Modern Java
01 Java Language And OOP Part I LAB
Java8
LISP: How I Learned To Stop Worrying And Love Parantheses
What is String in Java?
Python by ganesh kavhar
06 Java Language And OOP Part VI
From Java 6 to Java 7 reference
Quick introduction to Java Garbage Collector (JVM GC)
Java intro
RIBBUN SOFTWARE
Java01
Best practices in Java
Why GC is eating all my CPU?
Ad

Similar to DevNexus 2018: Learn Java 8, lambdas and functional programming (20)

PDF
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
KEY
Scala Introduction
PDF
Clojure for Java developers
PDF
55j7
ODP
Getting started with Clojure
KEY
The Why and How of Scala at Twitter
PPTX
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
PPTX
A brief tour of modern Java
PPTX
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
PDF
Java programming basics
PDF
Introduction to clojure
PDF
Clojure Interoperability
PPTX
Software Uni Conf October 2014
PDF
Clojure - A new Lisp
PPTX
Java 7 Whats New(), Whats Next() from Oredev
PPT
whats new in java 8
PDF
Clojure - A practical LISP for the JVM
PDF
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
PDF
Scala, Akka, and Play: An Introduction on Heroku
PPTX
New Features of JAVA SE8
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
Scala Introduction
Clojure for Java developers
55j7
Getting started with Clojure
The Why and How of Scala at Twitter
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
A brief tour of modern Java
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Java programming basics
Introduction to clojure
Clojure Interoperability
Software Uni Conf October 2014
Clojure - A new Lisp
Java 7 Whats New(), Whats Next() from Oredev
whats new in java 8
Clojure - A practical LISP for the JVM
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Scala, Akka, and Play: An Introduction on Heroku
New Features of JAVA SE8
Ad

More from Henri Tremblay (16)

PDF
OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?
PPTX
Confoo 2018: Être pragmatique
PPTX
Do you know your mock? - Madras JUG 20171028
PDF
Be Pragmatic - JavaOne 2017
PPTX
Generics and Lambda survival guide - DevNexus 2017
PDF
JavaOne 2016 - Learn Lambda and functional programming
PPTX
Java 8, lambdas, generics: How to survive? - NYC Java Meetup Group
PPTX
Confoo 2016: Initiation aux tests de charge
PPTX
Generics and Lambdas cocktail explained - Montreal JUG
PPTX
Réactif, parallèle, asynchrone. Pourquoi!
PPTX
Perf university
PPTX
Microbenchmarking with JMH
PPTX
Lambdas and Generics (long version) - Bordeaux/Toulouse JUG
PPTX
Vivre en parallèle - Softshake 2013
PPTX
Performance perpétuelle (Devopsdays Paris 2013)
PPTX
DevoxxFR 2013: Lambda are coming. Meanwhile, are you sure we've mastered the ...
OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?
Confoo 2018: Être pragmatique
Do you know your mock? - Madras JUG 20171028
Be Pragmatic - JavaOne 2017
Generics and Lambda survival guide - DevNexus 2017
JavaOne 2016 - Learn Lambda and functional programming
Java 8, lambdas, generics: How to survive? - NYC Java Meetup Group
Confoo 2016: Initiation aux tests de charge
Generics and Lambdas cocktail explained - Montreal JUG
Réactif, parallèle, asynchrone. Pourquoi!
Perf university
Microbenchmarking with JMH
Lambdas and Generics (long version) - Bordeaux/Toulouse JUG
Vivre en parallèle - Softshake 2013
Performance perpétuelle (Devopsdays Paris 2013)
DevoxxFR 2013: Lambda are coming. Meanwhile, are you sure we've mastered the ...

Recently uploaded (20)

PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
cuic standard and advanced reporting.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Cloud computing and distributed systems.
PDF
KodekX | Application Modernization Development
PPTX
A Presentation on Artificial Intelligence
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Machine learning based COVID-19 study performance prediction
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
The Rise and Fall of 3GPP – Time for a Sabbatical?
NewMind AI Weekly Chronicles - August'25 Week I
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
cuic standard and advanced reporting.pdf
Review of recent advances in non-invasive hemoglobin estimation
Cloud computing and distributed systems.
KodekX | Application Modernization Development
A Presentation on Artificial Intelligence
Building Integrated photovoltaic BIPV_UPV.pdf
The AUB Centre for AI in Media Proposal.docx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Approach and Philosophy of On baking technology
Advanced methodologies resolving dimensionality complications for autism neur...
Per capita expenditure prediction using model stacking based on satellite ima...
Dropbox Q2 2025 Financial Results & Investor Presentation
Unlocking AI with Model Context Protocol (MCP)
Understanding_Digital_Forensics_Presentation.pptx
Machine learning based COVID-19 study performance prediction

DevNexus 2018: Learn Java 8, lambdas and functional programming