SlideShare une entreprise Scribd logo
1  sur  44
Télécharger pour lire hors ligne
JAVA 8
Features and other cool stuff
A bit of history
● (“1.0”) -> LocalDate.of(1996, Month.JANUARY, 23)
● (“1.1”) -> LocalDate.of(1997, Month.FEBRUARY, 19)
● (“1.2”) -> LocalDate.of(1998, Month.DECEMBER, 9)
● (“1.3”) -> LocalDate.of(2000, Month.MAY, 8)
● (“1.4”) -> LocalDate.of(2002, Month.FEBRUARY, 6)
● (“1.5”) -> LocalDate.of(2004, Month.SEPTEMBER, 30)
● (“1.6”) -> LocalDate.of(2006, Month.DECEMBER, 11)
● (“1.7”) -> LocalDate.of(2011, Month.JULY, 7)
● (“1.8”) -> LocalDate.of(2014, Month.MARCH, 15)
JAVA 8, what more ?
● JAVA 8 is for JAVA 7 what JAVA 5 was for JAVA 1.4
● Lot’s of cool stuff
● Finally fonctional programming oriented
● With great power comes great responsability
● Ok, let’s dive into
Lambdas : let’s blow your mind
Lambdas : let’s blow your mind
Arrays.asList( "a", "b", "d" ).forEach( ( String e ) -> System.out.println( e ));
Arrays.asList( "a", "b", "d" ).forEach( e -> {
System.out.print( e );
System.out.print( e );
} );
Arrays.asList( "a", "b", "d" ).forEach( e -> System.out.println( e ) );
Lambdas : some explanations
● Anonymous method
● To unlearn what you’ve learned, you have to
● (argtype arg...) -> { return some expression.. probably using these arguments }
● Type inference : JVM compiler guess for you args types
● Welcome to functional programming !
Functional interfaces : let’s be friends
Functional interfaces : let’s be friends
● Interfaces with only ONE abstract method
● Can contains static and default method (next slide, don’t panic)
● Most of generic functional use case already in java.util.function package
○ Function, Supplier, Consumer, Predicate, etc.
● The backbone of lambda
@FunctionalInterface
public interface Functional {
void method();
}
Interface’s Default/Static Methods
Interface’s Default Methods : abstract death ?
● Not required to be implemented
● Inherited by default
● Overridden allowed
● Public visibility only
Interface’s Default Methods : abstract death ?
private interface Defaulable {
// Interfaces now allow default methods, the implementer may or
// may not implement (override) them.
default String notRequired() {
return "Default implementation";
}
}
private static class DefaultableImpl implements Defaulable {
}
private static class OverridableImpl implements Defaulable {
@Override
public String notRequired() {
return "Overridden implementation";
}
}
Interface’s Static Methods : tooling in interface
● Act as static class method
● An interface can now contain all the tooling
private interface DefaulableFactory {
// Interfaces now allow static methods
static Defaulable create( Supplier< Defaulable > supplier ) {
return supplier.get();
}
}
Method References : let’s take some shortcuts
Method References : let’s take some shortcuts
● Another way, more concise, to refer directly to existing methods
● Constructor reference
● Static method reference
● Instance method reference
● Instance method reference using Class
Method reference : example please !
public class Example {
public int add(int a, int b) {
return a + b;
}
public static int mul(int a, int b) {
return a * b;
}
public String lower(String a) {
return a.toLowerCase();
}
public void printDate(Date date) {
System.out.println(date);
}
public void oper(IntBinaryOperator operator, int a, int b) {
System.out.println(operator.applyAsInt(a, b));
}
public void operS(Function<String, String> stringOperator, String a) {
System.out.println(stringOperator.apply(a));
}
public GregorianCalendar operC(Supplier<GregorianCalendar> supplier) {
return supplier.get();
}
}
Constructor reference
ex.operC(()->{ return new GregorianCalendar();})
ex.operC(GregorianCalendar::new);
● Lambda way
● Method reference way
Static method reference
● Lambda way
● Method reference way
ex.oper((a, b) -> Example.mul(a, b), 1, 2);
ex.oper(Example::mul, 1, 2);
Instance method reference
● Lambda way
● Method reference way
ex.oper((a, b) -> ex.add(a, b), 1, 2);
ex.oper(ex::add, 1, 2);
Instance method reference using class
● Lambda way
● Method reference way
ex.operS(String::toLowerCase, "STRING");
ex.operS(s->s.toLowerCase(), "STRING");
Method References : WARNING !!!
Should be assignable to a functionnal interface
Repeating annotations : hide me this
Repeating annotations : hide me this
● Same annotation can be repeat several times
● How to
@Schedule(dayOfMonth="last")
@Schedule(dayOfWeek="Fri", hour="23")
public void doPeriodicCleanup() { ... }
@Repeatable(Schedules.class)
public @interface Schedule {
String dayOfMonth() default "first";
String dayOfWeek() default "Mon";
int hour() default 12;
}
public @interface Schedules {
Schedule[] value();
}
Extended Annotations Support : annotation everywhere !
Extended Annotations Support : annotation everywhere !
● ElementType.TYPE_USE -> Annotation on type use
● ElementType.TYPE_PARAMETER -> Annotation on type variable
@NonNull String name; // Type use
List<@NonNull String> names; // Type parameter
class UnmodifiableList<T> implements @Readonly List<@Readonly T>
{...}
email = (@Email String) input;
new @Information MyObject();
void doSomething() throws @ImportantForMe MyException { ... }
Parameter names : for reflection lovers only
Parameter names : for introspection lovers only
JVM arg : -parameter
Optional is not an option : end of NullPointer ?
Optional< String > fullName = Optional.ofNullable( null );
System.out.println( "Full Name is set? " + fullName.isPresent() );
System.out.println( "Full Name: " + fullName.orElseGet( () -> "[none]" ) );
System.out.println( fullName.map( s -> "Hey " + s + "!" ).orElse( "Hey Stranger!" ) );
Full Name is set? false
Full Name: [none]
Hey Stranger!
Optional is not an option : end of NullPointer ?
Optional< String > firstName = Optional.of( "Tom" );
System.out.println( "First Name is set? " + firstName.isPresent() );
System.out.println( "First Name: " + firstName.orElseGet( () -> "[none]" ) );
System.out.println( firstName.map( s -> "Hey " + s + "!" ).orElse( "Hey Stranger!" ) );
First Name is set? true
First Name: Tom
Hey Tom!
Optional is not an option : end of NullPointer ?
Streams : THIS IS map/reduce !!!
● Create a pipeline made of operations
● Terminal operation could produce another data store
● Parallelization
Streams : THIS IS map/reduce !!!
final Collection< Task > tasks = Arrays.asList(
new Task( Status.OPEN, 5 ),
new Task( Status.OPEN, 13 ),
new Task( Status.CLOSED, 8 )
);
// Calculate total points of all active tasks using sum()
final long totalPointsOfOpenTasks = tasks
.stream()
.filter( task -> task.getStatus() == Status.OPEN )
.mapToInt( Task::getPoints )
.sum();
System.out.println( "Total points: " + totalPointsOfOpenTasks );
Total points: 18
Streams : THIS IS map/reduce !!!
final Collection< Task > tasks = Arrays.asList(
new Task( Status.OPEN, 5 ),
new Task( Status.OPEN, 13 ),
new Task( Status.CLOSED, 8 )
);
// Group tasks by their status
final Map< Status, List< Task > > map = tasks
.stream()
.collect( Collectors.groupingBy( Task::getStatus ) );
System.out.println( map );
{CLOSED=[[CLOSED, 8]], OPEN=[[OPEN, 5], [OPEN, 13]]}
Streams : THIS IS map/reduce !!!
final Collection< Task > tasks = Arrays.asList(
new Task( Status.OPEN, 5 ),
new Task( Status.OPEN, 13 ),
new Task( Status.CLOSED, 8 )
);
// Calculate the weight of each tasks (as percent of total points)
final Collection< String > result = tasks
.stream() // Stream< String >
.mapToInt( Task::getPoints ) // IntStream
.asLongStream() // LongStream
.mapToDouble( points -> points / totalPoints ) // DoubleStream
.boxed() // Stream< Double >
.mapToLong( weigth -> ( long )( weigth * 100 ) ) // LongStream
.mapToObj( percentage -> percentage + "%" ) // Stream< String>
.collect( Collectors.toList() ); // List< String >
System.out.println( result );
[19%, 50%, 30%]
Streams : THIS IS map/reduce !!!
Date/Time API : Joda time was here...
● Inspired by JODA Time : made by developpers for developpers
● One package : java.time
● IMMUTABLE by design
Date/Time API : Joda time was here...
Date/Time API : Clock
// Get the system clock as UTC offset
final Clock clock = Clock.systemUTC();
System.out.println( clock.instant() );
System.out.println( clock.millis() );
2014-04-12T15:19:29.282Z
1397315969360
Date/Time API : LocalDate / LocalTime
// Get the local date and local time
final LocalDate date = LocalDate.now();
final LocalDate dateFromClock = LocalDate.now( clock );
System.out.println( date );
System.out.println( dateFromClock );
// Get the local date and local time
final LocalTime time = LocalTime.now();
final LocalTime timeFromClock = LocalTime.now( clock );
System.out.println( time );
System.out.println( timeFromClock );
2014-04-12
2014-04-12
11:25:54.568
15:25:54.568
Date/Time API : ZoneDateTime
// Get the zoned date/time
final Clock clock = Clock.systemUTC();
final ZonedDateTime zonedDatetime = ZonedDateTime.now();
final ZonedDateTime zonedDatetimeFromClock =
ZonedDateTime.now( clock );
final ZonedDateTime zonedDatetimeFromZone =
ZonedDateTime.now( ZoneId.of( "America/Los_Angeles" ) );
System.out.println( zonedDatetime );
System.out.println( zonedDatetimeFromClock );
System.out.println( zonedDatetimeFromZone );
2014-04-12T11:47:01.017-04:00
[America/New_York]
2014-04-12T15:47:01.017Z
2014-04-12T08:47:01.017-07:00
[America/Los_Angeles]
Date/Time API : Duration
// Get duration between two dates
final LocalDateTime from =
LocalDateTime.of( 2014, Month.APRIL, 16, 0, 0, 0 );
final LocalDateTime to =
LocalDateTime.of( 2015, Month.APRIL, 16, 23, 59, 59 );
final Duration duration = Duration.between( from, to );
System.out.println( "Duration in days: " + duration.toDays() );
System.out.println( "Duration in hours: " + duration.toHours() );
Duration in days: 365
Duration in hours: 8783
And so many other things
And so many other things
● Nashorn JavaScript Engine : evaluate JavaScript in JAVA
● Base64 standard support
○ URL-friendly encoder/decoder
○ MIME-friendly encoder/decoder
● Parallel Arrays
● Class dependency analyzer : jdeps
● XX:PermSize / XX:MaxPermSize respectivly replaced by XX:MetaSpaceSize
/ XX:MaxMetaSpaceSize
● String.join() / Objects.nonNull()
● Reflection api support TypeName, GenericString, access Generic type, etc.
● ...
Java 8
Java 8

Contenu connexe

Tendances

Functional Reactive Programming with RxJS
Functional Reactive Programming with RxJSFunctional Reactive Programming with RxJS
Functional Reactive Programming with RxJSstefanmayer13
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015Michiel Borkent
 
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015NAVER / MusicPlatform
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the webMichiel Borkent
 
How to Think in RxJava Before Reacting
How to Think in RxJava Before ReactingHow to Think in RxJava Before Reacting
How to Think in RxJava Before ReactingIndicThreads
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for AndroidTomáš Kypta
 
Functional Reactive Programming (FRP): Working with RxJS
Functional Reactive Programming (FRP): Working with RxJSFunctional Reactive Programming (FRP): Working with RxJS
Functional Reactive Programming (FRP): Working with RxJSOswald Campesato
 
Think Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSAdam L Barrett
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJSKyung Yeol Kim
 
Something about Golang
Something about GolangSomething about Golang
Something about GolangAnton Arhipov
 
The Ring programming language version 1.8 book - Part 86 of 202
The Ring programming language version 1.8 book - Part 86 of 202The Ring programming language version 1.8 book - Part 86 of 202
The Ring programming language version 1.8 book - Part 86 of 202Mahmoud Samir Fayed
 
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...CodeFest
 
Hierarchical free monads and software design in fp
Hierarchical free monads and software design in fpHierarchical free monads and software design in fp
Hierarchical free monads and software design in fpAlexander Granin
 
ReactiveCocoa Goodness - Part I of II
ReactiveCocoa Goodness - Part I of IIReactiveCocoa Goodness - Part I of II
ReactiveCocoa Goodness - Part I of IImanuelmaly
 
Virtual machine and javascript engine
Virtual machine and javascript engineVirtual machine and javascript engine
Virtual machine and javascript engineDuoyi Wu
 

Tendances (20)

Functional Reactive Programming with RxJS
Functional Reactive Programming with RxJSFunctional Reactive Programming with RxJS
Functional Reactive Programming with RxJS
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
 
Full Stack Clojure
Full Stack ClojureFull Stack Clojure
Full Stack Clojure
 
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the web
 
How to Think in RxJava Before Reacting
How to Think in RxJava Before ReactingHow to Think in RxJava Before Reacting
How to Think in RxJava Before Reacting
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
 
Functional Reactive Programming (FRP): Working with RxJS
Functional Reactive Programming (FRP): Working with RxJSFunctional Reactive Programming (FRP): Working with RxJS
Functional Reactive Programming (FRP): Working with RxJS
 
Kotlin, why?
Kotlin, why?Kotlin, why?
Kotlin, why?
 
Think Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJS
 
Introduction to java 8 stream api
Introduction to java 8 stream apiIntroduction to java 8 stream api
Introduction to java 8 stream api
 
Comparing JVM languages
Comparing JVM languagesComparing JVM languages
Comparing JVM languages
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJS
 
Angular2 rxjs
Angular2 rxjsAngular2 rxjs
Angular2 rxjs
 
Something about Golang
Something about GolangSomething about Golang
Something about Golang
 
The Ring programming language version 1.8 book - Part 86 of 202
The Ring programming language version 1.8 book - Part 86 of 202The Ring programming language version 1.8 book - Part 86 of 202
The Ring programming language version 1.8 book - Part 86 of 202
 
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
 
Hierarchical free monads and software design in fp
Hierarchical free monads and software design in fpHierarchical free monads and software design in fp
Hierarchical free monads and software design in fp
 
ReactiveCocoa Goodness - Part I of II
ReactiveCocoa Goodness - Part I of IIReactiveCocoa Goodness - Part I of II
ReactiveCocoa Goodness - Part I of II
 
Virtual machine and javascript engine
Virtual machine and javascript engineVirtual machine and javascript engine
Virtual machine and javascript engine
 

Similaire à Java 8

New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 itiAhmed mar3y
 
Introduction to Dart
Introduction to DartIntroduction to Dart
Introduction to DartRamesh Nair
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript DevelopmentJussi Pohjolainen
 
Php 5.6 From the Inside Out
Php 5.6 From the Inside OutPhp 5.6 From the Inside Out
Php 5.6 From the Inside OutFerenc Kovács
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8Martin Toshev
 
The GO Language : From Beginners to Gophers
The GO Language : From Beginners to GophersThe GO Language : From Beginners to Gophers
The GO Language : From Beginners to GophersAlessandro Sanino
 
От Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовОт Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовYandex
 
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel ZikmundNDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel ZikmundKarel Zikmund
 
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfOrtus Solutions, Corp
 
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go WrongJDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go WrongPROIDEA
 
What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?Christophe Porteneuve
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()daewon jeong
 
Functional Programming in Java 8
Functional Programming in Java 8Functional Programming in Java 8
Functional Programming in Java 8Omar Bashir
 
Intro to Reactive Thinking and RxJava 2
Intro to Reactive Thinking and RxJava 2Intro to Reactive Thinking and RxJava 2
Intro to Reactive Thinking and RxJava 2JollyRogers5
 
Making a Process
Making a ProcessMaking a Process
Making a ProcessDavid Evans
 

Similaire à Java 8 (20)

New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
Writing MySQL UDFs
Writing MySQL UDFsWriting MySQL UDFs
Writing MySQL UDFs
 
R - the language
R - the languageR - the language
R - the language
 
Introduction to Dart
Introduction to DartIntroduction to Dart
Introduction to Dart
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Php 5.6 From the Inside Out
Php 5.6 From the Inside OutPhp 5.6 From the Inside Out
Php 5.6 From the Inside Out
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
The GO Language : From Beginners to Gophers
The GO Language : From Beginners to GophersThe GO Language : From Beginners to Gophers
The GO Language : From Beginners to Gophers
 
От Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовОт Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей Родионов
 
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel ZikmundNDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
 
Using zone.js
Using zone.jsUsing zone.js
Using zone.js
 
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
 
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go WrongJDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
 
mapreduce ppt.ppt
mapreduce ppt.pptmapreduce ppt.ppt
mapreduce ppt.ppt
 
What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?
 
L3.fa14.ppt
L3.fa14.pptL3.fa14.ppt
L3.fa14.ppt
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()
 
Functional Programming in Java 8
Functional Programming in Java 8Functional Programming in Java 8
Functional Programming in Java 8
 
Intro to Reactive Thinking and RxJava 2
Intro to Reactive Thinking and RxJava 2Intro to Reactive Thinking and RxJava 2
Intro to Reactive Thinking and RxJava 2
 
Making a Process
Making a ProcessMaking a Process
Making a Process
 

Plus de Cédric GILLET (6)

Agile
AgileAgile
Agile
 
GraphQL + relay
GraphQL + relayGraphQL + relay
GraphQL + relay
 
Spring.io
Spring.ioSpring.io
Spring.io
 
GraphQL
GraphQLGraphQL
GraphQL
 
Le nouveau portail
Le nouveau portailLe nouveau portail
Le nouveau portail
 
Liquibase
LiquibaseLiquibase
Liquibase
 

Dernier

Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Dernier (20)

Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Java 8

  • 1. JAVA 8 Features and other cool stuff
  • 2. A bit of history ● (“1.0”) -> LocalDate.of(1996, Month.JANUARY, 23) ● (“1.1”) -> LocalDate.of(1997, Month.FEBRUARY, 19) ● (“1.2”) -> LocalDate.of(1998, Month.DECEMBER, 9) ● (“1.3”) -> LocalDate.of(2000, Month.MAY, 8) ● (“1.4”) -> LocalDate.of(2002, Month.FEBRUARY, 6) ● (“1.5”) -> LocalDate.of(2004, Month.SEPTEMBER, 30) ● (“1.6”) -> LocalDate.of(2006, Month.DECEMBER, 11) ● (“1.7”) -> LocalDate.of(2011, Month.JULY, 7) ● (“1.8”) -> LocalDate.of(2014, Month.MARCH, 15)
  • 3. JAVA 8, what more ? ● JAVA 8 is for JAVA 7 what JAVA 5 was for JAVA 1.4 ● Lot’s of cool stuff ● Finally fonctional programming oriented ● With great power comes great responsability ● Ok, let’s dive into
  • 4. Lambdas : let’s blow your mind
  • 5. Lambdas : let’s blow your mind Arrays.asList( "a", "b", "d" ).forEach( ( String e ) -> System.out.println( e )); Arrays.asList( "a", "b", "d" ).forEach( e -> { System.out.print( e ); System.out.print( e ); } ); Arrays.asList( "a", "b", "d" ).forEach( e -> System.out.println( e ) );
  • 6. Lambdas : some explanations ● Anonymous method ● To unlearn what you’ve learned, you have to ● (argtype arg...) -> { return some expression.. probably using these arguments } ● Type inference : JVM compiler guess for you args types ● Welcome to functional programming !
  • 7. Functional interfaces : let’s be friends
  • 8. Functional interfaces : let’s be friends ● Interfaces with only ONE abstract method ● Can contains static and default method (next slide, don’t panic) ● Most of generic functional use case already in java.util.function package ○ Function, Supplier, Consumer, Predicate, etc. ● The backbone of lambda @FunctionalInterface public interface Functional { void method(); }
  • 10. Interface’s Default Methods : abstract death ? ● Not required to be implemented ● Inherited by default ● Overridden allowed ● Public visibility only
  • 11. Interface’s Default Methods : abstract death ? private interface Defaulable { // Interfaces now allow default methods, the implementer may or // may not implement (override) them. default String notRequired() { return "Default implementation"; } } private static class DefaultableImpl implements Defaulable { } private static class OverridableImpl implements Defaulable { @Override public String notRequired() { return "Overridden implementation"; } }
  • 12. Interface’s Static Methods : tooling in interface ● Act as static class method ● An interface can now contain all the tooling private interface DefaulableFactory { // Interfaces now allow static methods static Defaulable create( Supplier< Defaulable > supplier ) { return supplier.get(); } }
  • 13. Method References : let’s take some shortcuts
  • 14. Method References : let’s take some shortcuts ● Another way, more concise, to refer directly to existing methods ● Constructor reference ● Static method reference ● Instance method reference ● Instance method reference using Class
  • 15. Method reference : example please ! public class Example { public int add(int a, int b) { return a + b; } public static int mul(int a, int b) { return a * b; } public String lower(String a) { return a.toLowerCase(); } public void printDate(Date date) { System.out.println(date); } public void oper(IntBinaryOperator operator, int a, int b) { System.out.println(operator.applyAsInt(a, b)); } public void operS(Function<String, String> stringOperator, String a) { System.out.println(stringOperator.apply(a)); } public GregorianCalendar operC(Supplier<GregorianCalendar> supplier) { return supplier.get(); } }
  • 16. Constructor reference ex.operC(()->{ return new GregorianCalendar();}) ex.operC(GregorianCalendar::new); ● Lambda way ● Method reference way
  • 17. Static method reference ● Lambda way ● Method reference way ex.oper((a, b) -> Example.mul(a, b), 1, 2); ex.oper(Example::mul, 1, 2);
  • 18. Instance method reference ● Lambda way ● Method reference way ex.oper((a, b) -> ex.add(a, b), 1, 2); ex.oper(ex::add, 1, 2);
  • 19. Instance method reference using class ● Lambda way ● Method reference way ex.operS(String::toLowerCase, "STRING"); ex.operS(s->s.toLowerCase(), "STRING");
  • 20. Method References : WARNING !!! Should be assignable to a functionnal interface
  • 21. Repeating annotations : hide me this
  • 22. Repeating annotations : hide me this ● Same annotation can be repeat several times ● How to @Schedule(dayOfMonth="last") @Schedule(dayOfWeek="Fri", hour="23") public void doPeriodicCleanup() { ... } @Repeatable(Schedules.class) public @interface Schedule { String dayOfMonth() default "first"; String dayOfWeek() default "Mon"; int hour() default 12; } public @interface Schedules { Schedule[] value(); }
  • 23. Extended Annotations Support : annotation everywhere !
  • 24. Extended Annotations Support : annotation everywhere ! ● ElementType.TYPE_USE -> Annotation on type use ● ElementType.TYPE_PARAMETER -> Annotation on type variable @NonNull String name; // Type use List<@NonNull String> names; // Type parameter class UnmodifiableList<T> implements @Readonly List<@Readonly T> {...} email = (@Email String) input; new @Information MyObject(); void doSomething() throws @ImportantForMe MyException { ... }
  • 25. Parameter names : for reflection lovers only
  • 26. Parameter names : for introspection lovers only JVM arg : -parameter
  • 27. Optional is not an option : end of NullPointer ?
  • 28. Optional< String > fullName = Optional.ofNullable( null ); System.out.println( "Full Name is set? " + fullName.isPresent() ); System.out.println( "Full Name: " + fullName.orElseGet( () -> "[none]" ) ); System.out.println( fullName.map( s -> "Hey " + s + "!" ).orElse( "Hey Stranger!" ) ); Full Name is set? false Full Name: [none] Hey Stranger! Optional is not an option : end of NullPointer ?
  • 29. Optional< String > firstName = Optional.of( "Tom" ); System.out.println( "First Name is set? " + firstName.isPresent() ); System.out.println( "First Name: " + firstName.orElseGet( () -> "[none]" ) ); System.out.println( firstName.map( s -> "Hey " + s + "!" ).orElse( "Hey Stranger!" ) ); First Name is set? true First Name: Tom Hey Tom! Optional is not an option : end of NullPointer ?
  • 30. Streams : THIS IS map/reduce !!!
  • 31. ● Create a pipeline made of operations ● Terminal operation could produce another data store ● Parallelization Streams : THIS IS map/reduce !!!
  • 32. final Collection< Task > tasks = Arrays.asList( new Task( Status.OPEN, 5 ), new Task( Status.OPEN, 13 ), new Task( Status.CLOSED, 8 ) ); // Calculate total points of all active tasks using sum() final long totalPointsOfOpenTasks = tasks .stream() .filter( task -> task.getStatus() == Status.OPEN ) .mapToInt( Task::getPoints ) .sum(); System.out.println( "Total points: " + totalPointsOfOpenTasks ); Total points: 18 Streams : THIS IS map/reduce !!!
  • 33. final Collection< Task > tasks = Arrays.asList( new Task( Status.OPEN, 5 ), new Task( Status.OPEN, 13 ), new Task( Status.CLOSED, 8 ) ); // Group tasks by their status final Map< Status, List< Task > > map = tasks .stream() .collect( Collectors.groupingBy( Task::getStatus ) ); System.out.println( map ); {CLOSED=[[CLOSED, 8]], OPEN=[[OPEN, 5], [OPEN, 13]]} Streams : THIS IS map/reduce !!!
  • 34. final Collection< Task > tasks = Arrays.asList( new Task( Status.OPEN, 5 ), new Task( Status.OPEN, 13 ), new Task( Status.CLOSED, 8 ) ); // Calculate the weight of each tasks (as percent of total points) final Collection< String > result = tasks .stream() // Stream< String > .mapToInt( Task::getPoints ) // IntStream .asLongStream() // LongStream .mapToDouble( points -> points / totalPoints ) // DoubleStream .boxed() // Stream< Double > .mapToLong( weigth -> ( long )( weigth * 100 ) ) // LongStream .mapToObj( percentage -> percentage + "%" ) // Stream< String> .collect( Collectors.toList() ); // List< String > System.out.println( result ); [19%, 50%, 30%] Streams : THIS IS map/reduce !!!
  • 35. Date/Time API : Joda time was here...
  • 36. ● Inspired by JODA Time : made by developpers for developpers ● One package : java.time ● IMMUTABLE by design Date/Time API : Joda time was here...
  • 37. Date/Time API : Clock // Get the system clock as UTC offset final Clock clock = Clock.systemUTC(); System.out.println( clock.instant() ); System.out.println( clock.millis() ); 2014-04-12T15:19:29.282Z 1397315969360
  • 38. Date/Time API : LocalDate / LocalTime // Get the local date and local time final LocalDate date = LocalDate.now(); final LocalDate dateFromClock = LocalDate.now( clock ); System.out.println( date ); System.out.println( dateFromClock ); // Get the local date and local time final LocalTime time = LocalTime.now(); final LocalTime timeFromClock = LocalTime.now( clock ); System.out.println( time ); System.out.println( timeFromClock ); 2014-04-12 2014-04-12 11:25:54.568 15:25:54.568
  • 39. Date/Time API : ZoneDateTime // Get the zoned date/time final Clock clock = Clock.systemUTC(); final ZonedDateTime zonedDatetime = ZonedDateTime.now(); final ZonedDateTime zonedDatetimeFromClock = ZonedDateTime.now( clock ); final ZonedDateTime zonedDatetimeFromZone = ZonedDateTime.now( ZoneId.of( "America/Los_Angeles" ) ); System.out.println( zonedDatetime ); System.out.println( zonedDatetimeFromClock ); System.out.println( zonedDatetimeFromZone ); 2014-04-12T11:47:01.017-04:00 [America/New_York] 2014-04-12T15:47:01.017Z 2014-04-12T08:47:01.017-07:00 [America/Los_Angeles]
  • 40. Date/Time API : Duration // Get duration between two dates final LocalDateTime from = LocalDateTime.of( 2014, Month.APRIL, 16, 0, 0, 0 ); final LocalDateTime to = LocalDateTime.of( 2015, Month.APRIL, 16, 23, 59, 59 ); final Duration duration = Duration.between( from, to ); System.out.println( "Duration in days: " + duration.toDays() ); System.out.println( "Duration in hours: " + duration.toHours() ); Duration in days: 365 Duration in hours: 8783
  • 41. And so many other things
  • 42. And so many other things ● Nashorn JavaScript Engine : evaluate JavaScript in JAVA ● Base64 standard support ○ URL-friendly encoder/decoder ○ MIME-friendly encoder/decoder ● Parallel Arrays ● Class dependency analyzer : jdeps ● XX:PermSize / XX:MaxPermSize respectivly replaced by XX:MetaSpaceSize / XX:MaxMetaSpaceSize ● String.join() / Objects.nonNull() ● Reflection api support TypeName, GenericString, access Generic type, etc. ● ...