SlideShare ist ein Scribd-Unternehmen logo
1 von 79
© Henri Tremblay 2015
Henri Tremblay
Senior Software Engineer
Terracotta, a Software AG company
Java 5,6,7,8,9,10,11: What did you miss?
[TUT4828]
@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
5
 11
Good old
New & shinny
8
8 minutes break (please do come back)
9
Show of hands
10
You voting for me
11
Questions
12
Java Delivery Process
13
Java 6 Java 7 Java 8
Old delivery process
5 years 3 years 3 years
14
Java 9 Java 10 Java 11
New delivery process
6 months 6 months 6 months
15
2006 20142007 2008 2009 2010 2011 2012 2013 20202015 2016 2017 2018 2019 2021 2022 2023 2024 2025 2026
Java 6 (last from Sun)
Java 7
Java 8 (LTS)
Java 5
Java 9
Java 10
Java 13
Java 12
Java 11 (LTS)
16
TL;DR
OracleJDK: Free and supported to 6 months
  LTS versions have extended ($$$) support by Oracle
  Identical to OpenJDK when free
OpenJDK: Free forever, not supported after 6 months
  Built by https://adoptopenjdk.net/
Other JVMs (Azul, IBM, RedHat, etc.)
  Supported by their vendor as they wish
A lot of “May” and “Possibly” in the party line
https://medium.com/@javachampions/java-is-still-free-
c02aef8c9e04
17
Funny fact
Java 9 è Java 17.9
Java 10 è Java 18.3
Java 11 è Java 18.9
java version "11-ea" 2018-09-25
Java(TM) SE Runtime Environment 18.9 (build 11-ea+26)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11-ea+26, mixed mode)
18
17.9 18.3 18.9 19.3 19.9 20.3 20.9 21.3 21.9 22.3 22.9 23.3 23.9 24.3 24.9 25.3 25.9
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
19
@Deprecated
is back
Stronger than ever
20
/**
* Counts the number of stack frames in this thread. The thread must
* be suspended.
*
* @return the number of stack frames in this thread.
* @throws IllegalThreadStateException if this thread is not
* suspended.
* @deprecated The definition of this call depends on {@link #suspend},
* which is deprecated. Further, the results of this call
* were never well-defined.
* This method is subject to removal in a future version of Java SE.
* @see StackWalker
*/
@Deprecated(since="1.2", forRemoval=true)
public native int countStackFrames();
21
Java 1.1
(1997)
22
Mustache instantiation
Hashtable map = new Hashtable() {{
put("key", "value");
}};
23
Modern mustache instantiation
Map<String, String> map = new HashMap<>() {{
put("key", "value");
}};
24
Modern map instantiation (Java 9)
Map<String, String> map =
Map.of("key", "value");
25
Slightly longer map instantiation
private Map<String, String> map = new HashMap<>();
{
map.put("key", "value");
}
26
Java 5
(2004)
27
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)
28
Type witness
MyClass.<List<String>> anyObject()
because you can’t
(List<String>) MyClass.anyObject()
29
Type witness
MyClass.<List<String>> anyObject()
because you can’t
(List<String>) MyClass.anyObject()
30
Java 6
(2006, last from Sun)
31
JAVA 6 BROUGHT.. PRETTY
MUCH NOTHING
(a bunch of performance improvements under the hood, better xml
parsing and the first scripting api)
32
Java 7
(2011, first from Oracle)
33
JAVA 7 BROUGHT A LOT OF
SYNTACTIC SUGAR
(plus invokeDynamic, forkJoin, better file IO)
34
Switch for strings
switch(s) {
case "hello":
return "world";
case "bonjour":
return "le monde";
}
35
Diamond operator
List<String> list = new ArrayList<>();
36
Binary integer literals and underscores
int i = 0b1110001111;
int i = 1_000_000;
37
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);
}
38
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
}
39
Auto Closeable
Real code you should do
InputStream in = new FileInputStream("allo.txt");
try {
// … do stuff
in.close();
} catch(IOException e) {
try {
in.close();
} catch(IOException e1) {
e.addSuppressed(e1);
}
throw e;
}
40
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
41
Java 8
(2014)
42
JAVA 8: LAMBDA!
(and also a new date API, default methods, metaspace, Nashorn,
JavaFX and CompletableFuture)
43
Base64 ;-)
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class Base64s {
public static void main(String[] args) {
final String text = "Base64 finally in Java 8!";
final String encoded = Base64
.getEncoder()
.encodeToString( text.getBytes( StandardCharsets.UTF_8 ) );
System.out.println( encoded );
final String decoded = new String(
Base64.getDecoder().decode( encoded ),
StandardCharsets.UTF_8 );
System.out.println( decoded );
}
}
44
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
45
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]
46
Lambda: 11th letter of the Greek alphabet
47
(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
48
This is a function:
This is a lambda:
Lambda calculus
49
c = coll.forEach(
(a, b) –> pow(a, 2) + pow(b, 2)
)
Functional programming
50
Lambda
// Classic
list.forEach(e -> System.out.println(e));
// Typed
list.forEach((String e) -> System.out.println(e));
// Multiline
list.forEach((String e) -> {
System.out.println(e);
});
// With closure
String greeting= "Hello ”;
list.forEach(e -> System.out.println(greeting + e));
51
Implicit final
List<String> list = new ArrayList<>();
String greeting = "Hello "; // no final required
list.forEach(s -> System.out.println(greeting + s));
list.forEach(new Consumer<String>() {
@Override public void accept(String s) {
System.out.println(greeting + s);
}
});
list.forEach(s -> greeting = “Hi”); // won’t compile
52
Interface default methods
public interface List<E> extends
Collection<E> {
default void replaceAll(UnaryOperator<E>
operator) {
// …
}
}
public interface A {
default void foo() { }
}
public interface B{
default void foo() { }
}
public class C implements A, B {} // forbidden
public class C implements A, B { // allowed
public void foo() { }
}
public static class D implements A, B { //
allowed
public void foo() {
A.super.foo();
}
}
53
Interface static methods
public interface IntStream {
static IntStream empty () {
return …;
}
}
IntStream stream = IntStream.empty ();
54
Mustache vol. 2
Map<Long, Person> persons = Map.of(
1L, new Person(12, "Marc"),
2L, new Person(58, "Pierre”)
);
persons.entrySet().stream()
.map(entry -> new Object() {
long id = entry.getKey();
String name = entry.getValue().getName();
})
.forEach(tuple -> {
System.out.println(tuple.id + ": " + tuple.name);
});
}
55
Everything is a lambda
public interface MyInterface {
int foo();
}
public void bar(MyInterface i) {
System.out.println(i.foo());
}
bar(() -> 4);
bar(new MyInterface() {
@Override public int foo() {
return 4;
}
});
JButton btn = new JButton();
btn.addActionListener(e -> {});
But it’s better to flag them
with
@FunctionalInterface
56
Method references
public static class Passenger {
public void inboard(Train train) {
System.out.println("Inboard " + train);
}
}
public static class Train {
public static Train create(Supplier< Train > supplier)
{
return supplier.get();
}
public static void paintBlue(Train train) {
System.out.println("Painted blue " + train);
}
public void repair() {
System.out.println( "Repaired " + this);
}
}
Train train = Train.create(Train::new); // constructor
List<Train> trains = Arrays.asList(train);
trains.forEach(Train::paintBlue); // static
method
trains.forEach(Train::repair); // instance
method
Passenger p = new Passenger();
trains.forEach(p::inboard); // instance
method taking this in param
trains.forEach(System.out::println); // useful!
57
Upside Down
public class MethodTest {
public class Foo {
static final String ERR_MESSAGE = "bad";
public void doIt() throws IllegalStateException {
throw new IllegalStateException(ERR_MESSAGE);
}
}
@Test
public void test() {
Foo foo = new Foo();
Throwable t = captureThrowable(foo::doIt);
assertThat(t)
.isInstanceOf(IllegalStateException.class)
.hasMessage(Foo.ERR_MESSAGE);
}
public static Throwable captureThrowable(Runnable r) {
Throwable result = null;
58
Streams
try(Stream<String> lines =
Files.lines(Paths.get("src/Streams.java"))) {
System.out.println(lines.findFirst());
}
59
Functional programming
List<String> list = new ArrayList<>();
int sum= list
.stream()
.filter(s -> s.startsWith("a"))
.mapToInt(String::length)
.sum();
List<Integer> length = list
.stream()
.map(String::length)
.collect(Collectors.toList());
60
Parallel
List<String> list = new ArrayList<>();
int sum = list
.parallelStream()
.filter(s -> s.startsWith("a"))
.mapToInt(String::length)
.sum();
Arrays.parallelSort(array);
61
Optional
try(Stream<String> lines =
Files.lines(Paths.get("src/Streams.java"))) {
System.out.println(lines.findFirst());
}
è  Optional[import java.io.IOException;]
Optional<String> findFirst();
Solution: lines.findFirst().get();
èimport java.io.IOException;
62
Java 9
(2017)
63
JAVA 9: MODULES!
(and G1 by default, var handles, new http client, jshell, jcmd,
immutable collections, unified JVM logging)
64
Improved try-with-resource
ByteArrayOutputStream in = new ByteArrayOutputStream();
try(in) {
}
65
Java 10
(March 2018)
66
JAVA 10: VAR
(application class-data sharing, GraalVM)
67
Keywords
  while, if, abstract, public, default,
class, enum (Java 5), _ (Java 9)
Restricted Keywords
  open, module, to, with
Literals
  true, false, null
Reserved identifier
var
What is var?
68
Java 11
(September 2018)
69
JAVA 11: CLEANUP
(and dynamic class-file constants, epsilon, java.xml, corba and
many J2EE modules removed, nashorn removed, ZGC, single file
program)
70
Prepare to do some stretching
Java 8 Java 9 Java 10 Java 11
What any sane person will want his/her framework to support
71
Prepare to do some stretching
Java 8 Java 9 Java 10 Java 11
What any sane person will want his/her framework to support
Unsafe.defineClass()
MethodHandles.defineClass()
Unsafe.defineClass()
removed
72
Prepare to do some stretching
Java 8 Java 9 Java 10 Java 11
What any sane person will want his/her framework to support
import java.xml.bind
--add-modules javax.xml.bind
--module-path containing
jaxb-api-2.4.0-xxx.jar
73
The End
74
Who has learned
something today?
?
75
Java Champions – Java is still free
https://medium.com/@javachampions/java-is-still-free-c02aef8c9e04
Adopt OpenJDK
https://adoptopenjdk.net/
Maurice Naftalin’s Lambda FAQ
http://www.lambdafaq.org/
Zeroturnaround Module Cheat Sheet
http://files.zeroturnaround.com/pdf/RebelLabs-Java-9-modules-cheat-sheet.pdf
Var styleguide
http://openjdk.java.net/projects/amber/LVTIstyle.html
Heinz Kabutz’s online course
https://javaspecialists.teachable.com/courses
Links
76
Modern Java in Action
  Raoul-Gabriel Urma and Mario Fusco
Mastering Lambdas
  Maurice Naftalin
Java 9 Modularity
  Sander Mak and Paul Bakker
Books
77
Caching in Applications still matters
[DEV5935]
 Henri Tremblay & Anthony Dahanne
Moscone West – Room 2007
Next talk
78
You voting for me
79
Questions? http://montreal-jug.org
? http://easymock.org
http://objenesis.org
http:/ehcache.org
Henri Tremblay
http://blog.tremblay.pro
@henri_tremblay

Weitere ähnliche Inhalte

Was ist angesagt?

DevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern JavaDevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern JavaHenri Tremblay
 
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningCarol McDonald
 
Compact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinCompact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinDmitry Pranchuk
 
Kotlin – the future of android
Kotlin – the future of androidKotlin – the future of android
Kotlin – the future of androidDJ Rausch
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongMario Fusco
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - StockholmJan Kronquist
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)Pavlo Baron
 
Predictably
PredictablyPredictably
Predictablyztellman
 
Java → kotlin: Tests Made Simple
Java → kotlin: Tests Made SimpleJava → kotlin: Tests Made Simple
Java → kotlin: Tests Made Simpleleonsabr
 
Clojure for Java developers
Clojure for Java developersClojure for Java developers
Clojure for Java developersJohn Stevenson
 
Kotlin 101 for Java Developers
Kotlin 101 for Java DevelopersKotlin 101 for Java Developers
Kotlin 101 for Java DevelopersChristoph Pickl
 
Java Puzzle
Java PuzzleJava Puzzle
Java PuzzleSFilipp
 
How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...Mario Fusco
 

Was ist angesagt? (20)

DevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern JavaDevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern Java
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 
Java Lab Manual
Java Lab ManualJava Lab Manual
Java Lab Manual
 
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
 
Compact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinCompact and safely: static DSL on Kotlin
Compact and safely: static DSL on Kotlin
 
2 P Seminar
2 P Seminar2 P Seminar
2 P Seminar
 
Kotlin – the future of android
Kotlin – the future of androidKotlin – the future of android
Kotlin – the future of android
 
Pattern Matching in Java 14
Pattern Matching in Java 14Pattern Matching in Java 14
Pattern Matching in Java 14
 
Clojure: a LISP for the JVM
Clojure: a LISP for the JVMClojure: a LISP for the JVM
Clojure: a LISP for the JVM
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are Wrong
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - Stockholm
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Predictably
PredictablyPredictably
Predictably
 
Java → kotlin: Tests Made Simple
Java → kotlin: Tests Made SimpleJava → kotlin: Tests Made Simple
Java → kotlin: Tests Made Simple
 
Kotlin meets Gadsu
Kotlin meets GadsuKotlin meets Gadsu
Kotlin meets Gadsu
 
Clojure for Java developers
Clojure for Java developersClojure for Java developers
Clojure for Java developers
 
Kotlin 101 for Java Developers
Kotlin 101 for Java DevelopersKotlin 101 for Java Developers
Kotlin 101 for Java Developers
 
Java Puzzle
Java PuzzleJava Puzzle
Java Puzzle
 
JVM Mechanics
JVM MechanicsJVM Mechanics
JVM Mechanics
 
How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...
 

Ähnlich wie OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?

Why is Java relevant? New features of Java8
Why is Java relevant? New features of Java8 Why is Java relevant? New features of Java8
Why is Java relevant? New features of Java8 xshyamx
 
Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Martijn Verburg
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneAndres Almiray
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevMattias Karlsson
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghStuart Roebuck
 
Pure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools RacePure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools RaceBaruch Sadogursky
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy PluginsPaul King
 
JavaOne 2016 - Learn Lambda and functional programming
JavaOne 2016 - Learn Lambda and functional programmingJavaOne 2016 - Learn Lambda and functional programming
JavaOne 2016 - Learn Lambda and functional programmingHenri Tremblay
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx FranceDavid Delabassee
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVMRafael Winterhalter
 
Beauty and the beast - Haskell on JVM
Beauty and the beast  - Haskell on JVMBeauty and the beast  - Haskell on JVM
Beauty and the beast - Haskell on JVMJarek Ratajski
 
Cascading Through Hadoop for the Boulder JUG
Cascading Through Hadoop for the Boulder JUGCascading Through Hadoop for the Boulder JUG
Cascading Through Hadoop for the Boulder JUGMatthew McCullough
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages VictorSzoltysek
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 

Ähnlich wie OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss? (20)

Why is Java relevant? New features of Java8
Why is Java relevant? New features of Java8 Why is Java relevant? New features of Java8
Why is Java relevant? New features of Java8
 
Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)
 
Java 5 and 6 New Features
Java 5 and 6 New FeaturesJava 5 and 6 New Features
Java 5 and 6 New Features
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Java
JavaJava
Java
 
Pure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools RacePure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools Race
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy Plugins
 
Mastering Java ByteCode
Mastering Java ByteCodeMastering Java ByteCode
Mastering Java ByteCode
 
JavaOne 2016 - Learn Lambda and functional programming
JavaOne 2016 - Learn Lambda and functional programmingJavaOne 2016 - Learn Lambda and functional programming
JavaOne 2016 - Learn Lambda and functional programming
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Java 10, Java 11 and beyond
Java 10, Java 11 and beyondJava 10, Java 11 and beyond
Java 10, Java 11 and beyond
 
55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
 
Beauty and the beast - Haskell on JVM
Beauty and the beast  - Haskell on JVMBeauty and the beast  - Haskell on JVM
Beauty and the beast - Haskell on JVM
 
Cascading Through Hadoop for the Boulder JUG
Cascading Through Hadoop for the Boulder JUGCascading Through Hadoop for the Boulder JUG
Cascading Through Hadoop for the Boulder JUG
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages
 
Modern Java Development
Modern Java DevelopmentModern Java Development
Modern Java Development
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 

Mehr von Henri Tremblay

Confoo 2018: Être pragmatique
Confoo 2018: Être pragmatiqueConfoo 2018: Être pragmatique
Confoo 2018: Être pragmatiqueHenri Tremblay
 
DevNexus 2018: Learn Java 8, lambdas and functional programming
DevNexus 2018: Learn Java 8, lambdas and functional programmingDevNexus 2018: Learn Java 8, lambdas and functional programming
DevNexus 2018: Learn Java 8, lambdas and functional programmingHenri Tremblay
 
Do you know your mock? - Madras JUG 20171028
Do you know your mock? - Madras JUG 20171028Do you know your mock? - Madras JUG 20171028
Do you know your mock? - Madras JUG 20171028Henri Tremblay
 
Be Pragmatic - JavaOne 2017
Be Pragmatic - JavaOne 2017Be Pragmatic - JavaOne 2017
Be Pragmatic - JavaOne 2017Henri Tremblay
 
Generics and Lambda survival guide - DevNexus 2017
Generics and Lambda survival guide - DevNexus 2017Generics and Lambda survival guide - DevNexus 2017
Generics and Lambda survival guide - DevNexus 2017Henri Tremblay
 
Java 8, lambdas, generics: How to survive? - NYC Java Meetup Group
Java 8, lambdas, generics: How to survive? - NYC Java Meetup GroupJava 8, lambdas, generics: How to survive? - NYC Java Meetup Group
Java 8, lambdas, generics: How to survive? - NYC Java Meetup GroupHenri Tremblay
 
Confoo 2016: Initiation aux tests de charge
Confoo 2016: Initiation aux tests de chargeConfoo 2016: Initiation aux tests de charge
Confoo 2016: Initiation aux tests de chargeHenri Tremblay
 
Generics and Lambdas cocktail explained - Montreal JUG
Generics and Lambdas cocktail explained  - Montreal JUGGenerics and Lambdas cocktail explained  - Montreal JUG
Generics and Lambdas cocktail explained - Montreal JUGHenri Tremblay
 
Réactif, parallèle, asynchrone. Pourquoi!
Réactif, parallèle, asynchrone. Pourquoi!Réactif, parallèle, asynchrone. Pourquoi!
Réactif, parallèle, asynchrone. Pourquoi!Henri Tremblay
 
Microbenchmarking with JMH
Microbenchmarking with JMHMicrobenchmarking with JMH
Microbenchmarking with JMHHenri Tremblay
 
Lambdas and Generics (long version) - Bordeaux/Toulouse JUG
Lambdas and Generics (long version) - Bordeaux/Toulouse JUGLambdas and Generics (long version) - Bordeaux/Toulouse JUG
Lambdas and Generics (long version) - Bordeaux/Toulouse JUGHenri Tremblay
 
Vivre en parallèle - Softshake 2013
Vivre en parallèle - Softshake 2013Vivre en parallèle - Softshake 2013
Vivre en parallèle - Softshake 2013Henri Tremblay
 
Performance perpétuelle (Devopsdays Paris 2013)
Performance perpétuelle (Devopsdays Paris 2013)Performance perpétuelle (Devopsdays Paris 2013)
Performance perpétuelle (Devopsdays Paris 2013)Henri Tremblay
 
DevoxxFR 2013: Lambda are coming. Meanwhile, are you sure we've mastered the ...
DevoxxFR 2013: Lambda are coming. Meanwhile, are you sure we've mastered the ...DevoxxFR 2013: Lambda are coming. Meanwhile, are you sure we've mastered the ...
DevoxxFR 2013: Lambda are coming. Meanwhile, are you sure we've mastered the ...Henri Tremblay
 

Mehr von Henri Tremblay (15)

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

Kürzlich hochgeladen

Governance in SharePoint Premium:What's in the box?
Governance in SharePoint Premium:What's in the box?Governance in SharePoint Premium:What's in the box?
Governance in SharePoint Premium:What's in the box?Juan Carlos Gonzalez
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
100+ ChatGPT Prompts for SEO Optimization
100+ ChatGPT Prompts for SEO Optimization100+ ChatGPT Prompts for SEO Optimization
100+ ChatGPT Prompts for SEO Optimizationarrow10202532yuvraj
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5DianaGray10
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"DianaGray10
 

Kürzlich hochgeladen (20)

Governance in SharePoint Premium:What's in the box?
Governance in SharePoint Premium:What's in the box?Governance in SharePoint Premium:What's in the box?
Governance in SharePoint Premium:What's in the box?
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
100+ ChatGPT Prompts for SEO Optimization
100+ ChatGPT Prompts for SEO Optimization100+ ChatGPT Prompts for SEO Optimization
100+ ChatGPT Prompts for SEO Optimization
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
 

OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?

  • 1. © Henri Tremblay 2015 Henri Tremblay Senior Software Engineer Terracotta, a Software AG company Java 5,6,7,8,9,10,11: What did you miss? [TUT4828] @henri_tremblay
  • 4. 4 Henri Tremblay •  More or less made possible class mocking and proxying •  Coined the term “partial mocking”
  • 5. 5 Henri Tremblay •  More or less made possible class mocking and proxying •  Coined the term “partial mocking”
  • 6. 6
  • 8. 8 8 minutes break (please do come back)
  • 13. 13 Java 6 Java 7 Java 8 Old delivery process 5 years 3 years 3 years
  • 14. 14 Java 9 Java 10 Java 11 New delivery process 6 months 6 months 6 months
  • 15. 15 2006 20142007 2008 2009 2010 2011 2012 2013 20202015 2016 2017 2018 2019 2021 2022 2023 2024 2025 2026 Java 6 (last from Sun) Java 7 Java 8 (LTS) Java 5 Java 9 Java 10 Java 13 Java 12 Java 11 (LTS)
  • 16. 16 TL;DR OracleJDK: Free and supported to 6 months   LTS versions have extended ($$$) support by Oracle   Identical to OpenJDK when free OpenJDK: Free forever, not supported after 6 months   Built by https://adoptopenjdk.net/ Other JVMs (Azul, IBM, RedHat, etc.)   Supported by their vendor as they wish A lot of “May” and “Possibly” in the party line https://medium.com/@javachampions/java-is-still-free- c02aef8c9e04
  • 17. 17 Funny fact Java 9 è Java 17.9 Java 10 è Java 18.3 Java 11 è Java 18.9 java version "11-ea" 2018-09-25 Java(TM) SE Runtime Environment 18.9 (build 11-ea+26) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11-ea+26, mixed mode)
  • 18. 18 17.9 18.3 18.9 19.3 19.9 20.3 20.9 21.3 21.9 22.3 22.9 23.3 23.9 24.3 24.9 25.3 25.9 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
  • 20. 20 /** * Counts the number of stack frames in this thread. The thread must * be suspended. * * @return the number of stack frames in this thread. * @throws IllegalThreadStateException if this thread is not * suspended. * @deprecated The definition of this call depends on {@link #suspend}, * which is deprecated. Further, the results of this call * were never well-defined. * This method is subject to removal in a future version of Java SE. * @see StackWalker */ @Deprecated(since="1.2", forRemoval=true) public native int countStackFrames();
  • 22. 22 Mustache instantiation Hashtable map = new Hashtable() {{ put("key", "value"); }};
  • 23. 23 Modern mustache instantiation Map<String, String> map = new HashMap<>() {{ put("key", "value"); }};
  • 24. 24 Modern map instantiation (Java 9) Map<String, String> map = Map.of("key", "value");
  • 25. 25 Slightly longer map instantiation private Map<String, String> map = new HashMap<>(); { map.put("key", "value"); }
  • 27. 27 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)
  • 28. 28 Type witness MyClass.<List<String>> anyObject() because you can’t (List<String>) MyClass.anyObject()
  • 29. 29 Type witness MyClass.<List<String>> anyObject() because you can’t (List<String>) MyClass.anyObject()
  • 31. 31 JAVA 6 BROUGHT.. PRETTY MUCH NOTHING (a bunch of performance improvements under the hood, better xml parsing and the first scripting api)
  • 32. 32 Java 7 (2011, first from Oracle)
  • 33. 33 JAVA 7 BROUGHT A LOT OF SYNTACTIC SUGAR (plus invokeDynamic, forkJoin, better file IO)
  • 34. 34 Switch for strings switch(s) { case "hello": return "world"; case "bonjour": return "le monde"; }
  • 36. 36 Binary integer literals and underscores int i = 0b1110001111; int i = 1_000_000;
  • 37. 37 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); }
  • 38. 38 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 }
  • 39. 39 Auto Closeable Real code you should do InputStream in = new FileInputStream("allo.txt"); try { // … do stuff in.close(); } catch(IOException e) { try { in.close(); } catch(IOException e1) { e.addSuppressed(e1); } throw e; }
  • 40. 40 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
  • 42. 42 JAVA 8: LAMBDA! (and also a new date API, default methods, metaspace, Nashorn, JavaFX and CompletableFuture)
  • 43. 43 Base64 ;-) import java.nio.charset.StandardCharsets; import java.util.Base64; public class Base64s { public static void main(String[] args) { final String text = "Base64 finally in Java 8!"; final String encoded = Base64 .getEncoder() .encodeToString( text.getBytes( StandardCharsets.UTF_8 ) ); System.out.println( encoded ); final String decoded = new String( Base64.getDecoder().decode( encoded ), StandardCharsets.UTF_8 ); System.out.println( decoded ); } }
  • 44. 44 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
  • 45. 45 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]
  • 46. 46 Lambda: 11th letter of the Greek alphabet
  • 47. 47 (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
  • 48. 48 This is a function: This is a lambda: Lambda calculus
  • 49. 49 c = coll.forEach( (a, b) –> pow(a, 2) + pow(b, 2) ) Functional programming
  • 50. 50 Lambda // Classic list.forEach(e -> System.out.println(e)); // Typed list.forEach((String e) -> System.out.println(e)); // Multiline list.forEach((String e) -> { System.out.println(e); }); // With closure String greeting= "Hello ”; list.forEach(e -> System.out.println(greeting + e));
  • 51. 51 Implicit final List<String> list = new ArrayList<>(); String greeting = "Hello "; // no final required list.forEach(s -> System.out.println(greeting + s)); list.forEach(new Consumer<String>() { @Override public void accept(String s) { System.out.println(greeting + s); } }); list.forEach(s -> greeting = “Hi”); // won’t compile
  • 52. 52 Interface default methods public interface List<E> extends Collection<E> { default void replaceAll(UnaryOperator<E> operator) { // … } } public interface A { default void foo() { } } public interface B{ default void foo() { } } public class C implements A, B {} // forbidden public class C implements A, B { // allowed public void foo() { } } public static class D implements A, B { // allowed public void foo() { A.super.foo(); } }
  • 53. 53 Interface static methods public interface IntStream { static IntStream empty () { return …; } } IntStream stream = IntStream.empty ();
  • 54. 54 Mustache vol. 2 Map<Long, Person> persons = Map.of( 1L, new Person(12, "Marc"), 2L, new Person(58, "Pierre”) ); persons.entrySet().stream() .map(entry -> new Object() { long id = entry.getKey(); String name = entry.getValue().getName(); }) .forEach(tuple -> { System.out.println(tuple.id + ": " + tuple.name); }); }
  • 55. 55 Everything is a lambda public interface MyInterface { int foo(); } public void bar(MyInterface i) { System.out.println(i.foo()); } bar(() -> 4); bar(new MyInterface() { @Override public int foo() { return 4; } }); JButton btn = new JButton(); btn.addActionListener(e -> {}); But it’s better to flag them with @FunctionalInterface
  • 56. 56 Method references public static class Passenger { public void inboard(Train train) { System.out.println("Inboard " + train); } } public static class Train { public static Train create(Supplier< Train > supplier) { return supplier.get(); } public static void paintBlue(Train train) { System.out.println("Painted blue " + train); } public void repair() { System.out.println( "Repaired " + this); } } Train train = Train.create(Train::new); // constructor List<Train> trains = Arrays.asList(train); trains.forEach(Train::paintBlue); // static method trains.forEach(Train::repair); // instance method Passenger p = new Passenger(); trains.forEach(p::inboard); // instance method taking this in param trains.forEach(System.out::println); // useful!
  • 57. 57 Upside Down public class MethodTest { public class Foo { static final String ERR_MESSAGE = "bad"; public void doIt() throws IllegalStateException { throw new IllegalStateException(ERR_MESSAGE); } } @Test public void test() { Foo foo = new Foo(); Throwable t = captureThrowable(foo::doIt); assertThat(t) .isInstanceOf(IllegalStateException.class) .hasMessage(Foo.ERR_MESSAGE); } public static Throwable captureThrowable(Runnable r) { Throwable result = null;
  • 59. 59 Functional programming List<String> list = new ArrayList<>(); int sum= list .stream() .filter(s -> s.startsWith("a")) .mapToInt(String::length) .sum(); List<Integer> length = list .stream() .map(String::length) .collect(Collectors.toList());
  • 60. 60 Parallel List<String> list = new ArrayList<>(); int sum = list .parallelStream() .filter(s -> s.startsWith("a")) .mapToInt(String::length) .sum(); Arrays.parallelSort(array);
  • 61. 61 Optional try(Stream<String> lines = Files.lines(Paths.get("src/Streams.java"))) { System.out.println(lines.findFirst()); } è  Optional[import java.io.IOException;] Optional<String> findFirst(); Solution: lines.findFirst().get(); èimport java.io.IOException;
  • 63. 63 JAVA 9: MODULES! (and G1 by default, var handles, new http client, jshell, jcmd, immutable collections, unified JVM logging)
  • 64. 64 Improved try-with-resource ByteArrayOutputStream in = new ByteArrayOutputStream(); try(in) { }
  • 66. 66 JAVA 10: VAR (application class-data sharing, GraalVM)
  • 67. 67 Keywords   while, if, abstract, public, default, class, enum (Java 5), _ (Java 9) Restricted Keywords   open, module, to, with Literals   true, false, null Reserved identifier var What is var?
  • 69. 69 JAVA 11: CLEANUP (and dynamic class-file constants, epsilon, java.xml, corba and many J2EE modules removed, nashorn removed, ZGC, single file program)
  • 70. 70 Prepare to do some stretching Java 8 Java 9 Java 10 Java 11 What any sane person will want his/her framework to support
  • 71. 71 Prepare to do some stretching Java 8 Java 9 Java 10 Java 11 What any sane person will want his/her framework to support Unsafe.defineClass() MethodHandles.defineClass() Unsafe.defineClass() removed
  • 72. 72 Prepare to do some stretching Java 8 Java 9 Java 10 Java 11 What any sane person will want his/her framework to support import java.xml.bind --add-modules javax.xml.bind --module-path containing jaxb-api-2.4.0-xxx.jar
  • 75. 75 Java Champions – Java is still free https://medium.com/@javachampions/java-is-still-free-c02aef8c9e04 Adopt OpenJDK https://adoptopenjdk.net/ Maurice Naftalin’s Lambda FAQ http://www.lambdafaq.org/ Zeroturnaround Module Cheat Sheet http://files.zeroturnaround.com/pdf/RebelLabs-Java-9-modules-cheat-sheet.pdf Var styleguide http://openjdk.java.net/projects/amber/LVTIstyle.html Heinz Kabutz’s online course https://javaspecialists.teachable.com/courses Links
  • 76. 76 Modern Java in Action   Raoul-Gabriel Urma and Mario Fusco Mastering Lambdas   Maurice Naftalin Java 9 Modularity   Sander Mak and Paul Bakker Books
  • 77. 77 Caching in Applications still matters [DEV5935]  Henri Tremblay & Anthony Dahanne Moscone West – Room 2007 Next talk