SlideShare uma empresa Scribd logo
1 de 142
Baixar para ler offline
@JosePaumard#50new8
50 new things we can do with Java 8
José Paumard
@JosePaumard
blog.paumard.org
@JosePaumard
new things we can do with
Java
Questions?
#50new8
@JosePaumard
Date
@JosePaumard#50new8
Date: Instant
An Instant is a point on the time line
Instant start = Instant.now() ;
Instant end = Instant.now() ;
@JosePaumard#50new8
Date: Duration
A « duration » is the amount of time between instants
Instant start = Instant.now() ;
Instant end = Instant.now() ;
Duration elapsed = Duration.between(start, end) ;
long millis = elapsed.toMillis() ;
@JosePaumard#50new8
Date: Duration
There is an arithmetic on durations
Instant start = Instant.now() ;
Instant end = Instant.now() ;
Duration elapsed = Duration.between(start, end) ;
long millis = elapsed.toMillis() ;
elapsed.plus(2L, TemporalUnit.SECONDS) ;
@JosePaumard#50new8
Date: Duration
The precision of the time line is 10-9 s (nanosecond)
@JosePaumard#50new8
Date: Duration
The precision of the time line is 10-9 s (nanosecond)
You think it’s high precision?
@JosePaumard#50new8
Date: Duration
The precision of the time line is 10-9 s (nanosecond)
You think it’s high precision?
Well the l of the
Higgs boson is 10-23 s
@JosePaumard#50new8
Date: LocalDate
A LocalDate is an « every day » date
LocalDate now = LocalDate.now() ;
LocalDate shakespeareDoB =
LocaleDate.of(1564, Month.APRIL, 23) ;
@JosePaumard#50new8
Date: Period
A « period » is the amount of time between local dates
LocalDate now = LocalDate.now() ;
LocalDate shakespeareDoB =
LocaleDate.of(1564, Month.APRIL, 23) ;
Period p = shakespeareDoB.until(now) ;
System.out.println("# years = " + p.getYears()) ;
@JosePaumard#50new8
Date: Period
A « period » is the amount of time between local dates
LocalDate now = LocalDate.now() ;
LocalDate shakespeareDoB =
LocaleDate.of(1564, Month.APRIL, 23) ;
Period p = shakespeareDoB.until(now) ;
System.out.println("# years = " + p.getYears()) ;
long days = shakespeareDoB.until(now, ChronoUnit.DAYS) ;
System.out.println("# days = " + days) ;
@JosePaumard#50new8
Date: TemporalAdjuster
Arithmetic with local dates
LocalDate now = LocalDate.now() ;
LocalDate nextSunday =
now.with(TemporalAdjuster.next(DayOfWeek.SUNDAY)) ;
@JosePaumard#50new8
Date: TemporalAdjuster
Arithmetic with local dates
A toolbox of 14 static methods
firstDayOfMonth(), lastDayOfYear()
firstDayOfNextMonth()
LocalDate now = LocalDate.now() ;
LocalDate nextSunday =
now.with(TemporalAdjuster.next(DayOfWeek.SUNDAY)) ;
@JosePaumard#50new8
Date: TemporalAdjuster
Arithmetic with local dates
A toolbox of 14 static methods
firstInMonth(DayOfWeek.MONDAY)
next(DayOfWeek.FRIDAY)
LocalDate now = LocalDate.now() ;
LocalDate nextSunday =
now.with(TemporalAdjuster.next(DayOfWeek.SUNDAY)) ;
@JosePaumard#50new8
Date: LocalTime
A LocalTime is an everyday time: ex. 10:20
LocalTime now = LocalTime.now() ;
LocalTime time = LocalTime.of(10, 20) ; // 10:20
@JosePaumard#50new8
Date: LocalTime
A LocalTime is an everyday time: ex. 10:20
LocalTime now = LocalTime.now() ;
LocalTime time = LocalTime.of(10, 20) ; // 10:20
LocalTime lunchTime = LocalTime.of(12, 30) ;
LocalTime coffeeTime = lunchTime.plusHours(2) ; // 14:20
@JosePaumard#50new8
Date: ZonedTime
Useful for localized times
Set<String> allZonesIds = ZoneId.getAvailableZoneIds() ;
String ukTZ = ZoneId.of("Europe/London") ;
@JosePaumard#50new8
Date: ZonedTime
Useful for localized times
System.out.println(
ZonedDateTime.of(
1564, Month.APRIL.getValue(), 23, // year / month / day
10, 0, 0, 0, // h / mn / s / nanos
ZoneId.of("Europe/London"))
); // prints 1564-04-23T10:00-00:01:15[Europe/London]
@JosePaumard#50new8
Date: ZonedTime
Arithmetic on localized time
ZonedDateTime currentMeeting =
ZonedDateTime.of(
LocalDate.of(2014, Month.APRIL, 18), // LocalDate
LocalTime.of(9, 30), // LocalTime
ZoneId.of("Europe/London")
);
ZonedDateTime nextMeeting =
currentMeeting.plus(Period.ofMonth(1));
@JosePaumard#50new8
Date: ZonedTime
Arithmetic on localized time
ZonedDateTime currentMeeting =
ZonedDateTime.of(
LocalDate.of(2014, Month.APRIL, 18), // LocalDate
LocalTime.of(9, 30), // LocalTime
ZoneId.of("Europe/London")
);
ZonedDateTime nextMeeting =
currentMeeting.plus(Period.ofMonth(1)) ;
ZonedDateTime nextMeetingUS =
nextMeeting.withZoneSameInstant(ZoneId.of("US/Central")) ;
@JosePaumard#50new8
Date: Formatter
Factory class: DateTimeFormatter
ZonedDateTime nextMeetingUS =
nextMeeting.withZoneSameInstant(ZoneId.of("US/Central"));
System.out.println(
DateTimeFormatter.ISO_DATE_TIME.format(nextMeetingUS)
);
// prints 2014-04-12T03:30:00-05:00[US/Central]
System.out.println(
DateTimeFormatter.RFC_1123_DATE_TIME.format(nextMeetingUS)
);
// prints Sat, 12 Apr 2014 03:30:00 -0500
@JosePaumard#50new8
Date: bridges with java.util.Date
Factory class: DateTimeFormatter
Date date = Date.from(instant); // API -> legacy
Instant instant = date.toInstant(); // legacy -> new API
@JosePaumard#50new8
Date: bridges with java.util.Date
Factory class: DateTimeFormatter
TimeStamp time = TimeStamp.from(instant); // API -> legacy
Instant instant = time.toInstant(); // legacy -> new API
Date date = Date.from(instant); // API -> legacy
Instant instant = date.toInstant(); // legacy -> new API
@JosePaumard#50new8
Date: bridges with java.util.Date
Factory class: DateTimeFormatter
Date date = Date.from(localDate); // API -> legacy
LocalDate localDate = date.toLocalDate(); // legacy -> new API
TimeStamp time = TimeStamp.from(instant); // API -> legacy
Instant instant = time.toInstant(); // legacy -> new API
Date date = Date.from(instant); // API -> legacy
Instant instant = date.toInstant(); // legacy -> new API
@JosePaumard#50new8
Date: bridges with java.util.Date
Factory class: DateTimeFormatter
Time time = Time.from(localTime); // API -> legacy
LocalTime localTime = time.toLocalTime(); // legacy -> new API
Date date = Date.from(localDate); // API -> legacy
LocalDate localDate = date.toLocalDate(); // legacy -> new API
TimeStamp time = TimeStamp.from(instant); // API -> legacy
Instant instant = time.toInstant(); // legacy -> new API
Date date = Date.from(instant); // API -> legacy
Instant instant = date.toInstant(); // legacy -> new API
String
@JosePaumard#50new8
Building a Stream on a String
Building a Stream on the letters of a String:
String s = "hello";
IntStream stream = s.chars(); // stream on the letters of s
@JosePaumard#50new8
Building a Stream on a String
Building a Stream on the letters of a String:
String s = "hello";
IntStream stream = s.chars(); // stream on the letters of s
s.chars()
.map(Character::toUpperCase)
.forEach(System.out::println);
@JosePaumard#50new8
Building a Stream on a String
Building a Stream on the letters of a String:
String s = "hello";
IntStream stream = s.chars(); // stream on the letters of s
s.chars()
.map(Character::toUpperCase)
.forEach(System.out::println);
> HELLO7269767679
@JosePaumard#50new8
Building a Stream on a String
Building a Stream on the letters of a String:
String s = "hello";
IntStream stream = s.chars(); // stream on the letters of s
s.chars() // IntStream
.map(Character::toUpperCase)
.forEach(System.out::println); // Prints an int!
> 7269767679
@JosePaumard#50new8
Building a Stream on a String
Building a Stream on the letters of a String:
String s = "hello";
IntStream stream = s.chars(); // stream on the letters of s
s.chars() // IntStream
.mapToObj(letter -> (char)letter) // Stream<Character>
.map(Character::toUpperCase)
.forEach(System.out::println); // Prints a Character
> HELLO
@JosePaumard#50new8
String: regular expressions
Building a Stream from a regexp
// book is a looooooooong String
Stream<String> words =
Pattern
.compile("[^p{javaLetter}]")
.splitAsStream(book) ;
@JosePaumard#50new8
String: concatenation
The newbie writes:
String s1 = "hello" ;
String s2 = " world!" ;
String s3 = s1 + " " + s2 ;
@JosePaumard#50new8
String: concatenation
The ignorant tells him to write:
StringBuffer sb1 = new StringBuffer("hello") ;
sb1.append(" world") ;
String s3 = sb1.toString() ;
(and is wrong)
@JosePaumard#50new8
String: concatenation
The seasonned dev tells him to write:
StringBuilder sb1 = new StringBuilder("hello") ;
sb1.append(" world") ;
String s3 = sb1.toString() ;
(and is wrong too…)
@JosePaumard#50new8
String: concatenation
Because the newbie is right (even if he doesn’t know)
String s1 = "hello" ;
String s2 = " world!" ;
String s3 = s1 + " " + s2 ;LINENUMBER 10 L2
NEW java/lang/StringBuilder
DUP
ALOAD 1
INVOKESTATIC java/lang/String.valueOf(Ljava/lang/Object;)Ljava/lang/String;
INVOKESPECIAL java/lang/StringBuilder.<init>(Ljava/lang/String;)V
LDC " "
INVOKEVIRTUAL java/lang/StringBuilder.append(Ljava/lang/String;)Ljava/lang/StringBuilder;
ALOAD 2
INVOKEVIRTUAL java/lang/StringBuilder.append(Ljava/lang/String;)Ljava/lang/StringBuilder;
INVOKEVIRTUAL java/lang/StringBuilder.toString()Ljava/lang/String;
ASTORE 3
@JosePaumard#50new8
String: concatenation
The Java 8 well-trained dev writes:
// The JDK 8 way
StringJoiner sj = new StringJoiner(", ") ;
sj.add("one").add("two").add("three") ;
String s = sj.toString() ;
System.out.println(s) ;
@JosePaumard#50new8
String: concatenation
The Java 8 well-trained dev writes:
And it prints:
// The JDK 8 way
StringJoiner sj = new StringJoiner(", ") ;
sj.add("one").add("two").add("three") ;
String s = sj.toString() ;
System.out.println(s) ;
> one, two, three
@JosePaumard#50new8
String: concatenation
The Java 8 well-trained dev writes:
And it prints:
// The JDK 8 way
StringJoiner sj = new StringJoiner(", ") ;
sj.add("one") ;
String s = sj.toString() ;
System.out.println(s) ;
> one
@JosePaumard#50new8
String: concatenation
The Java 8 well-trained dev writes:
And it prints:
// The JDK 8 way
StringJoiner sj = new StringJoiner(", ", "{", "}") ;
sj.add("one").add("two").add("three") ;
String s = sj.toString() ;
System.out.println(s) ;
> {one, two, three}
@JosePaumard#50new8
String: concatenation
The Java 8 well-trained dev writes:
And it prints:
// The JDK 8 way
StringJoiner sj = new StringJoiner(", ", "{", "}") ;
sj.add("one") ;
String s = sj.toString() ;
System.out.println(s) ;
> {one}
@JosePaumard#50new8
String: concatenation
The Java 8 well-trained dev writes:
And it prints:
// The JDK 8 way
StringJoiner sj = new StringJoiner(", ", "{", "}") ;
// we dont put anything in it
String s = sj.toString() ;
System.out.println(s) ;
> {}
@JosePaumard#50new8
String: concatenation
And it’s nearly accessible from the String class itself:
And it prints:
// From the String class, with a vararg
String s = String.join(", ", "one", "two", "three");
System.out.println(s);
> one, two, three
@JosePaumard#50new8
String: concatenation
And it’s nearly accessible from the String class itself:
And it prints:
// From the String class, with an Iterable
String [] tab = {"one", "two", "three"} ;
String s = String.join(", ", tab) ;
System.out.println(s) ;
> one, two, three
Numbers
@JosePaumard#50new8
Numbers: new methods
Method max, min, sum
// max method available on number wrapper classes
long max = Long.max(1L, 2L);
long sum = Long.sum(1L, 2L);
@JosePaumard#50new8
Numbers: new methods
Method max, min, sum
Is it really that useful?
// max method available on number wrapper classes
long max = Long.max(1L, 2L);
long sum = Long.sum(1L, 2L);
@JosePaumard#50new8
Numbers: new methods
Method max, min, sum
Is it really that useful?
// max method available on number wrapper classes
long max = Long.max(1L, 2L);
long sum = Long.sum(1L, 2L);
persons.stream()
.map(Person::getAge)
.reduce(0, (a1, a2) -> Integer.max(a1, a2));
@JosePaumard#50new8
Numbers: new methods
Method max, min, sum
Is it really that useful? Nice to write method references
// max method available on number wrapper classes
long max = Long.max(1L, 2L);
long sum = Long.sum(1L, 2L);
persons.stream()
.map(Person::getAge)
.reduce(0, Integer::max);
@JosePaumard#50new8
Numbers: new methods
Method max, min, sum
// max method available on number wrapper classes
long max = Long.max(1L, 2L);
long sum = Long.sum(1L, 2L);
persons.stream()
.mapToInt(Person::getAge)
.max();
@JosePaumard#50new8
Numbers: new methods
Method max, min, sum
// max method available on number wrapper classes
long max = Long.max(1L, 2L);
long sum = Long.sum(1L, 2L);
persons.stream()
.max(Comparator.comparingBy(Person::getAge));
@JosePaumard#50new8
Numbers: new methods
Hashcode computation
// JDK 7
long l = 3141592653589793238L;
int hash = new Long(l).hashCode(); // -1985256439
@JosePaumard#50new8
Numbers: new methods
Hashcode computation
// JDK 7
long l = 3141592653589793238L;
int hash = new Long(l).hashCode(); // -1985256439
// JDK 8
long l = 3141592653589793238L;
int hash = Long.hashCode(l); // -1985256439
I/O
@JosePaumard#50new8
I/O: reading text files
Stream extends AutoCloseable
// Java 7 : try with resources and use of Paths
Path path = Paths.get("d:", "tmp", "debug.log");
try (Stream<String> stream = Files.lines(path)) {
stream.filter(line -> line.contains("ERROR"))
.findFirst()
.ifPresent(System.out::println);
} catch (IOException ioe) {
// handle the exception
}
@JosePaumard#50new8
I/O: reading text files
Files.list returns the content of the directory
// Java 7 : try with resources and use of Paths
Path path = Paths.get("c:", "windows");
try (Stream<Path> stream = Files.list(path)) {
stream.filter(path -> path.toFile().isDirectory())
.forEach(System.out::println);
} catch (IOException ioe) {
// handle the exception
}
@JosePaumard#50new8
I/O: reading a tree of subdirs
Files.walk returns the content of the subtree
// Java 7 : try with resources and use of Paths
Path path = Paths.get("c:", "windows");
try (Stream<Path> stream = Files.walk(path)) {
stream.filter(path -> path.toFile().isDirectory())
.forEach(System.out::println);
} catch (IOException ioe) {
// handle the exception
}
@JosePaumard#50new8
I/O: reading a tree of subdirs
Files.walk returns the content of the subtree, limit the depth
// Java 7 : try with resources and use of Paths
Path path = Paths.get("c:", "windows");
try (Stream<Path> stream = Files.walk(path, 2)) {
stream.filter(path -> path.toFile().isDirectory())
.forEach(System.out::println);
} catch (IOException ioe) {
// handle the exception
}
List
@JosePaumard#50new8
Iterable: forEach
ForEach: consumes the elements
Doesn’t work on arrays
// method forEach defined on Iterable
List<String> strings =
Arrays.asList("one", "two", "three") ;
strings.forEach(System.out::println) ;
> one, two, three
@JosePaumard#50new8
Collection: removeIf
Removes an object, takes a Predicate
Collection<String> strings =
Arrays.asList("one", "two", "three", "four");
// works « in place », no Collections.unmodifiable...
Collection<String> list = new ArrayList<>(strings);
// returns true if the list has been modified
boolean b = list.removeIf(s -> s.length() > 4);
> one, two, four
@JosePaumard#50new8
List: replaceAll
Replaces an object with its transform
Collection<String> strings =
Arrays.asList("one", "two", "three", "four");
// works « in place », no Collections.unmodifiable...
Collection<String> list = new ArrayList<>(strings);
// returns nothing
list.replaceAll(String::toUpperCase);
> ONE, TWO, THREE, FOUR
@JosePaumard#50new8
List: sort
Sorts a List in place, takes a Comparator
Collection<String> strings =
Arrays.asList("one", "two", "three", "four");
// works « in place », no Collections.unmodifiable...
Collection<String> list = new ArrayList<>(strings);
// returns nothing
list.sort(Comparator.naturalOrder()) ;
> four, one, three, two
Comparator
@JosePaumard#50new8
Comparator!
What else?
Comparator.naturalOrder() ;
@JosePaumard#50new8
Comparator!
What else?
Comparator.naturalOrder()
public static
<T extends Comparable<? super T>> Comparator<T> naturalOrder() {
return (Comparator<T>)
Comparators.NaturalOrderComparator.INSTANCE;
}
@JosePaumard#50new8
Comparator!
enum NaturalOrderComparator
implements Comparator<Comparable<Object>> {
INSTANCE; // What is this???
}
@JosePaumard#50new8
Comparator!
enum NaturalOrderComparator
implements Comparator<Comparable<Object>> {
INSTANCE; // OMG: a SINGLETON!!!
}
public class MySingleton {
INSTANCE;
private MySingleton() {}
public static MySingleton getInstance() {
// some buggy double-checked locking code
return INSTANCE;
}
}
@JosePaumard#50new8
Comparator!
enum NaturalOrderComparator
implements Comparator<Comparable<Object>> {
INSTANCE;
public int compare(Comparable<Object> c1, Comparable<Object> c2) {
return c1.compareTo(c2);
}
}
@JosePaumard#50new8
Comparator!
enum NaturalOrderComparator
implements Comparator<Comparable<Object>> {
INSTANCE;
public int compare(Comparable<Object> c1, Comparable<Object> c2) {
return c1.compareTo(c2);
}
public Comparator<Comparable<Object>> reversed() {
return Comparator.reverseOrder();
}
}
@JosePaumard#50new8
The good ol’ way!
Comparator!
// comparison using the last name
Comparator<Person> compareLastName =
new Comparator<Person>() {
@Override
public int compare(Person p1, Person p2) {
return p1.getLastName().compareTo(p2.getLastName());
}
};
@JosePaumard#50new8
Comparator!
// comparison using the last name then the first name
Comparator<Person> compareLastNameThenFirstName =
new Comparator<Person>() {
@Override
public int compare(Person p1, Person p2) {
int lastNameComparison =
p1.getLastName().compareTo(p2.getLastName());
return lastNameComparison == 0 ?
p2.getFirstName().compareTo(p2.getFirstName());
lastNameComparison;
}
};
@JosePaumard#50new8
Comparator!
The JDK 8 way!
Comparator.comparingBy(Person::getLastName); // static method
@JosePaumard#50new8
Comparator!
The JDK 8 way!
Comparator.comparingBy(Person::getLastName) // static method
.thenComparing(Person::getFirstName); // default method
@JosePaumard#50new8
Comparator!
The JDK 8 way!
Comparator.comparingBy(Person::getLastName) // static method
.thenComparing(Person::getFirstName) // default method
.thenComparing(Person::getAge);
@JosePaumard#50new8
Comparator!
Dont like the natural order?
Comparator<Person> comp = Comparator.naturalOrder();
Comparator<Person> reversedComp = Comparator.reversedOrder();
@JosePaumard#50new8
Comparator!
Dont like the natural order?
Comparator<Person> comp = Comparator.comparingBy(Person::getLastName);
Comparator<Person> reversedComp = comp.reversed();
@JosePaumard#50new8
Comparator!
And what about null values?
Comparator<Person> comp =
Comparator.naturalOrder();
@JosePaumard#50new8
Comparator!
And what about null values?
Comparator<Person> comp =
Comparator.nullsFirst(Comparator.naturalOrder());
@JosePaumard#50new8
Comparator!
And what about null values?
Comparator<Person> comp =
Comparator.nullsFirst(Comparator.naturalOrder());
Comparator<Person> comp =
Comparator.nullsLast(Comparator.naturalOrder());
Map
@JosePaumard#50new8
Map: forEach
Takes a BiConsumer
// the existing map
Map<String, Person> map = ... ;
map.forEach(
(key, value) -> System.out.println(key + " -> " + value)
) ;
@JosePaumard#50new8
Map: get
What happens if key is not in the map?
// the existing map
Map<String, Person> map = ... ;
Person p = map.get(key);
@JosePaumard#50new8
Map: get
// the existing map
Map<String, Person> map = ... ;
Person p = map.getOrDefault(key, Person.DEFAULT_PERSON);
@JosePaumard#50new8
Map: put
// the existing map
Map<String, Person> map = ... ;
map.put(key, person);
@JosePaumard#50new8
Map: putIfAbsent
// the existing map
Map<String, Person> map = ... ;
map.put(key, person);
map.putIfAbsent(key, person);
@JosePaumard#50new8
Map: replace
Replaces a value from its key
// the existing map
Map<String, Person> map = ... ;
// key, newValue
map.replace("six", john) ;
// key, oldValue, newValue
map.replace("six", peter, john) ;
@JosePaumard#50new8
Map: replaceAll
Replaces all the values from the map, using a l
// the existing map
Map<String, Person> map = ... ;
// key, oldValue
map.replaceAll(
(key, value) -> key + " -> " + value ;
) ;
@JosePaumard#50new8
Map: remove
Removes a key / value pair if it’s there
// the existing map
Map<String, Person> map = ... ;
// key, oldValue
map.remove("six", john) ;
@JosePaumard#50new8
Map: compute
Computes a value from the existing key / value pair and a l
// the existing map
Map<String, Person> map = ... ;
// key, oldValue
map.compute(
key,
(key, person) -> key + "::" + person // person can be null
) ;
@JosePaumard#50new8
Map: computeIfAbsent
Computes a value from a key that is not in the map
// the existing map
Map<String, Person> map = ... ;
// key, no existing value
map.computeIfAbsent(
key,
key -> person
) ;
@JosePaumard#50new8
Map: computeIfPresent
Computes a value from the existing key / value pair and a l
// the existing map
Map<String, Person> map = ... ;
// key, the existing value
map.computeIfPresent(
key, person,
(key, person) -> newPerson // person cannot be null
) ;
@JosePaumard#50new8
Map: merge
Computes the new value from the existing value, the newly
added value and a l
// the existing map
Map<String, Person> map = ... ;
// key, otherValue
map.merge(
key,
otherValue,
(value, otherValue) -> value.concat(", ").concat(otherValue)
) ;
@JosePaumard#50new8
Building bimaps
Making bimaps becomes sooo easy!
// the existing map
Map<String, Map<String, Person>> map = ... ;
// key, newValue
map.putIfAbsent(
"one",
(key) -> HashMap::new
).put("two", john);
Arrays
Parallel
@JosePaumard#50new8
Parallel Arrays
Arrays.parallelSetAll
long [] array = new long [...] ;
Arrays.parallelSetAll(array, index -> index % 3) ;
System.out.println(Arrays.toString(array)) ;
@JosePaumard#50new8
Parallel Arrays
Arrays.parallelPrefix: fold right
long [] array = new long [...] ;
Arrays.parallelPrefix(array, (l1, l2) -> l1 + l2) ;
System.out.println(Arrays.toString(array)) ;
long [] array = {1L, 1L, 1L, 1L} ;
> [1, 2, 3, 4]
@JosePaumard#50new8
Parallel Arrays
Arrays.parallelSort: in place sorting
long [] array = new long [...] ;
Arrays.parallelSort(array) ;
System.out.println(Arrays.toString(array)) ;
Completable
Future
@JosePaumard#50new8
CompletableFuture
Extension of Future
CompletableFuture<String> page =
CompletableFuture.supplyAsync(
) ;
@JosePaumard#50new8
CompletableFuture
Extension of Future
CompletableFuture<String> page =
CompletableFuture.supplyAsync(
() ->
readWebPage(url) // returns String
) ;
@JosePaumard#50new8
CompletableFuture
Now we can create pipelines
CompletableFuture.supplyAsync(
() ->
readWebPage(url)
)
.thenApply(
content -> getImages(content) // returns a List<Image>
) ; // returns a CompletableFuture<List<Image>>
@JosePaumard#50new8
CompletableFuture
Now we can create pipelines
CompletableFuture.supplyAsync(
() ->
readWebPage(url)
)
.thenApply(
content -> getImages(content) // returns a List<Image>
)
.thenAccept(
images -> images.forEach(System.out::println)
);
@JosePaumard#50new8
CompletableFuture
thenCompose(): does not wrap the result in a CF
CompletableFuture.supplyAsync(
() ->
readWebPage(url)
)
.thenCompose(
content -> getImages(content) // returns CF<List<Image>>
)
@JosePaumard#50new8
CompletableFuture
allOf: returns when all the tasks are done (see also anyOf)
CompletableFuture.allOf(
CompletableFuture.supplyAsync(
() ->
readWebPage(url)
)
.thenCompose(content -> getImages(content))
.thenApply(image -> writeToDisk(image))
)
.join() ;
@JosePaumard#50new8
CompletableFuture
thenCombine: can combine more than one CF
The l is applied once the two CF have completed
CompletableFuture cf1 = ... ;
CompletableFuture cf2 = ... ;
cf1.thenCombine(cf2, (b1, b2) -> b1 & b2) ; // can combine
// the results of CFs
@JosePaumard#50new8
CompletableFuture
thenCombine: can combine more than one CF
The l is applied once the two CF have completed
Also: thenAcceptBoth, runAfterBoth
CompletableFuture cf1 = ... ;
CompletableFuture cf2 = ... ;
cf1.thenCombine(cf2, (b1, b2) -> b1 & b2) ; // can combine
// the results of CFs
@JosePaumard#50new8
CompletableFuture
applyToEither: takes the first available result
CompletableFuture cf1 = ... ;
CompletableFuture cf2 = ... ;
cf1.applyToEither(cf2, (b) -> ...) ; // applies to the first
// CF that returns
@JosePaumard#50new8
CompletableFuture
applyToEither: takes the first available result
acceptEither, runAfterEither
CompletableFuture cf1 = ... ;
CompletableFuture cf2 = ... ;
cf1.applyToEither(cf2, (b) -> ...) ; // applies to the first
// CF that returns
Concurrence
@JosePaumard#50new8
Atomic variables
From Java 5:
AtomicLong atomic = new AtomicLong() ;
long l1 = atomic.incrementAndGet() ;
@JosePaumard#50new8
Atomic variables
Java 8 brings:
AtomicLong atomic = new AtomicLong() ;
long l1 = atomic.incrementAndGet() ;
long l2 = atomic.updateAndGet(l -> l*2 + 1) ;
@JosePaumard#50new8
Atomic variables
Java 8 brings:
AtomicLong atomic = new AtomicLong() ;
long l1 = atomic.incrementAndGet() ;
long l2 = atomic.updateAndGet(l -> l*2 + 1) ;
long l3 = atomic.accumulateAndGet(12L, (l1, l2) -> l1 % l2) ;
@JosePaumard#50new8
LongAdder
From Java 8:
LongAdded adder = new LongAdder() ;
adder.increment() ; // in a thread
adder.increment() ; // in a 2nd thread
adder.increment() ; // in a 3rd thread
long sum = adder.sum() ;
@JosePaumard#50new8
LongAccumulator
Same thing, with l:
LongAccumulator accu =
new LongAccumulator((l1, l2) -> Long.max(l1, l2), 0L) ;
accu.accumulate(value1) ; // in a thread
accu.accumulate(value2) ; // in a 2nd thread
accu.accumulate(value2) ; // in a 3rd thread
long sum = accu.longValue() ;
@JosePaumard#50new8
StampedLock
A regular lock, with optimistic read
long stamp = sl.writeLock() ;
try {
...
} finally {
sl.unlockWrite(stamp) ;
}
long stamp = sl.readLock() ;
try {
...
} finally {
sl.unlockRead(stamp) ;
}
StampedLock sl= new StampedLock() ;
@JosePaumard#50new8
StampedLock
A regular lock, with optimistic read
Exclusive read / write, but…
long stamp = sl.writeLock() ;
try {
...
} finally {
sl.unlockWrite(stamp) ;
}
long stamp = sl.readLock() ;
try {
...
} finally {
sl.unlockRead(stamp) ;
}
StampedLock sl= new StampedLock() ;
@JosePaumard#50new8
StampedLock
A regular lock, with optimistic read
StampedLock sl= new StampedLock() ;
long stamp = sl.tryOptimisticRead() ;
// here we read a variable that can be changed in another thread
if (lock.validate(stamp)) {
// the read was not concurrent
} else {
// another thread acquired a write lock
}
ConcurrentConcurrent
HashMap
@JosePaumard#50new8
ConcurrentHashMap
The old ConcurrentHashMap V7 has been removed
Thread safe
No locking ≠ ConcurrentHashMap V7
New methods (a lot…)
@JosePaumard#50new8
ConcurrentHashMap
6000 lines of code
@JosePaumard#50new8
ConcurrentHashMap
6000 lines of code
54 member classes
@JosePaumard#50new8
ConcurrentHashMap
6000 lines of code
54 member classes
FYI: 58 classes in java.util.concurrent
@JosePaumard#50new8
ConcurrentHashMap
6000 lines of code
54 member classes
FYI: 58 classes in java.util.concurrent
New patterns!
@JosePaumard#50new8
ConcurrentHashMap
Forget about size()
int count = map.size() ; // should not be used
count = map.mappingCount() ; // new method
@JosePaumard#50new8
ConcurrentHashMap
Forget about size()
int count = map.size() ; // should not be used
long count = map.mappingCount() ; // new method
@JosePaumard#50new8
ConcurrentHashMap
Search() method
search(), searchKey(), searchValue(), searchEntry()
Returns the 1st element that matches the predicate
ConcurrentHashMap<Integer, String> map = ... ;
map.search(10, (key, value) -> value.length() < key) ;
@JosePaumard#50new8
ConcurrentHashMap
Search() method
search(), searchKey(), searchValue(), searchEntry()
Returns the 1st element that matches the predicate
ConcurrentHashMap<Integer, String> map = ... ;
map.search(10, (key, value) -> value.length() < key) ;
@JosePaumard#50new8
ConcurrentHashMap
Search() method
If there are more than 10 elements, then the search will be
conducted in parallel!
ConcurrentHashMap<Integer, String> map = ... ;
map.search(10, (key, value) -> value.length() < key) ;
@JosePaumard#50new8
ConcurrentHashMap
Search() method
If there are more than 10 elements, then the search will be
conducted in parallel!
One can pass 0 or Long.MAX_VALUE
ConcurrentHashMap<Integer, String> map = ... ;
map.search(10, (key, value) -> value.length() < key) ;
@JosePaumard#50new8
ConcurrentHashMap
ForEach
forEach(), forEachKey(), forEachEntries()
ConcurrentHashMap<Integer, String> map = ... ;
map.forEach(10,
(key, value) ->
System.out.println(String.join(key, "->", value)
) ;
@JosePaumard#50new8
ConcurrentHashMap
Reduction
reduce(), reduceKey(), reduceEntries()
ConcurrentHashMap<Integer, String> map = ... ;
map.reduce(10,
(key, value) -> value.getName(), // transformation
(name1, name2) -> name1.length() > name2.length() ?
name1 : name2) // reduction
) ;
@JosePaumard#50new8
No ConcurrentHashSet
But…
Set<String> set = ConcurrentHashMap.newKeySet() ;
@JosePaumard#50new8
No ConcurrentHashSet
But…
Creates a concurrent hashmap in which the values are
Boolean.TRUE
Acts as a concurrent set
Set<String> set = ConcurrentHashMap.newKeySet() ;
Thank you!
@JosePaumard
#50new8

Mais conteúdo relacionado

Mais procurados

Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2José Paumard
 
Asynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsAsynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsPiotr Pelczar
 
Java Boilerplate Busters
Java Boilerplate BustersJava Boilerplate Busters
Java Boilerplate BustersHamletDRC
 
The algebra of library design
The algebra of library designThe algebra of library design
The algebra of library designLeonardo Borges
 
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistVoxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistAnton Arhipov
 
Callbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptCallbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptŁukasz Kużyński
 
Ast transformations
Ast transformationsAst transformations
Ast transformationsHamletDRC
 
Leveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyLeveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyDavid Gómez García
 
AST Transformations
AST TransformationsAST Transformations
AST TransformationsHamletDRC
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahNick Plante
 
A deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio moduleA deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio moduleSaúl Ibarra Corretgé
 
DjangoCon US 2011 - Monkeying around at New Relic
DjangoCon US 2011 - Monkeying around at New RelicDjangoCon US 2011 - Monkeying around at New Relic
DjangoCon US 2011 - Monkeying around at New RelicGraham Dumpleton
 
Avoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jscacois
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptjnewmanux
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsAnton Arhipov
 
Riga Dev Day 2016 - Having fun with Javassist
Riga Dev Day 2016 - Having fun with JavassistRiga Dev Day 2016 - Having fun with Javassist
Riga Dev Day 2016 - Having fun with JavassistAnton Arhipov
 
JavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with JavassistJavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with JavassistAnton Arhipov
 
Java9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadJava9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadDavid Gómez García
 
The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)Domenic Denicola
 

Mais procurados (20)

Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2
 
Java Full Throttle
Java Full ThrottleJava Full Throttle
Java Full Throttle
 
Asynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsAsynchronous programming done right - Node.js
Asynchronous programming done right - Node.js
 
Java Boilerplate Busters
Java Boilerplate BustersJava Boilerplate Busters
Java Boilerplate Busters
 
The algebra of library design
The algebra of library designThe algebra of library design
The algebra of library design
 
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistVoxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with Javassist
 
Callbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptCallbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascript
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Leveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyLeveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results Asynchrhonously
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
 
A deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio moduleA deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio module
 
DjangoCon US 2011 - Monkeying around at New Relic
DjangoCon US 2011 - Monkeying around at New RelicDjangoCon US 2011 - Monkeying around at New Relic
DjangoCon US 2011 - Monkeying around at New Relic
 
Avoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.js
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java Agents
 
Riga Dev Day 2016 - Having fun with Javassist
Riga Dev Day 2016 - Having fun with JavassistRiga Dev Day 2016 - Having fun with Javassist
Riga Dev Day 2016 - Having fun with Javassist
 
JavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with JavassistJavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with Javassist
 
Java9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadJava9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidad
 
The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)
 

Destaque

Linked to ArrayList: the full story
Linked to ArrayList: the full storyLinked to ArrayList: the full story
Linked to ArrayList: the full storyJosé Paumard
 
ArrayList et LinkedList sont dans un bateau
ArrayList et LinkedList sont dans un bateauArrayList et LinkedList sont dans un bateau
ArrayList et LinkedList sont dans un bateauJosé Paumard
 
50 nouvelles choses que l'on peut faire avec Java 8
50 nouvelles choses que l'on peut faire avec Java 850 nouvelles choses que l'on peut faire avec Java 8
50 nouvelles choses que l'on peut faire avec Java 8José Paumard
 
Autumn collection JavaOne 2014
Autumn collection JavaOne 2014Autumn collection JavaOne 2014
Autumn collection JavaOne 2014José Paumard
 
50 nouvelles choses que l'on peut faire en Java 8
50 nouvelles choses que l'on peut faire en Java 850 nouvelles choses que l'on peut faire en Java 8
50 nouvelles choses que l'on peut faire en Java 8José Paumard
 
Going reactive in java
Going reactive in javaGoing reactive in java
Going reactive in javaJosé Paumard
 
Java 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava ComparisonJava 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava ComparisonJosé Paumard
 
Déploiement d'une application Java EE dans Azure
Déploiement d'une application Java EE dans AzureDéploiement d'une application Java EE dans Azure
Déploiement d'une application Java EE dans AzureJosé Paumard
 
Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJosé Paumard
 
HighLoad++ 2009 In-Memory Data Grids
HighLoad++ 2009 In-Memory Data GridsHighLoad++ 2009 In-Memory Data Grids
HighLoad++ 2009 In-Memory Data GridsAlexey Kharlamov
 
Phoenix for Rubyists
Phoenix for RubyistsPhoenix for Rubyists
Phoenix for RubyistsMike North
 
Hazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSHazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSuzquiano
 
Async Gateway или Разработка системы распределенных вычислений с нуля
Async Gateway или Разработка системы распределенных вычислений с нуляAsync Gateway или Разработка системы распределенных вычислений с нуля
Async Gateway или Разработка системы распределенных вычислений с нуляVitebsk Miniq
 
API Asynchrones en Java 8
API Asynchrones en Java 8API Asynchrones en Java 8
API Asynchrones en Java 8José Paumard
 
Алексей Николаенков, Devexperts
Алексей Николаенков, DevexpertsАлексей Николаенков, Devexperts
Алексей Николаенков, DevexpertsNata_Churda
 
Amazon cloud – готовим вместе
Amazon cloud – готовим вместеAmazon cloud – готовим вместе
Amazon cloud – готовим вместеVitebsk Miniq
 
Hazelcast for Terracotta Users
Hazelcast for Terracotta UsersHazelcast for Terracotta Users
Hazelcast for Terracotta UsersHazelcast
 

Destaque (20)

Linked to ArrayList: the full story
Linked to ArrayList: the full storyLinked to ArrayList: the full story
Linked to ArrayList: the full story
 
ArrayList et LinkedList sont dans un bateau
ArrayList et LinkedList sont dans un bateauArrayList et LinkedList sont dans un bateau
ArrayList et LinkedList sont dans un bateau
 
Free your lambdas
Free your lambdasFree your lambdas
Free your lambdas
 
50 nouvelles choses que l'on peut faire avec Java 8
50 nouvelles choses que l'on peut faire avec Java 850 nouvelles choses que l'on peut faire avec Java 8
50 nouvelles choses que l'on peut faire avec Java 8
 
Autumn collection JavaOne 2014
Autumn collection JavaOne 2014Autumn collection JavaOne 2014
Autumn collection JavaOne 2014
 
50 nouvelles choses que l'on peut faire en Java 8
50 nouvelles choses que l'on peut faire en Java 850 nouvelles choses que l'on peut faire en Java 8
50 nouvelles choses que l'on peut faire en Java 8
 
Going reactive in java
Going reactive in javaGoing reactive in java
Going reactive in java
 
Java 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava ComparisonJava 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava Comparison
 
Déploiement d'une application Java EE dans Azure
Déploiement d'une application Java EE dans AzureDéploiement d'une application Java EE dans Azure
Déploiement d'une application Java EE dans Azure
 
Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patterns
 
HighLoad++ 2009 In-Memory Data Grids
HighLoad++ 2009 In-Memory Data GridsHighLoad++ 2009 In-Memory Data Grids
HighLoad++ 2009 In-Memory Data Grids
 
Phoenix for Rubyists
Phoenix for RubyistsPhoenix for Rubyists
Phoenix for Rubyists
 
Hazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSHazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMS
 
Async Gateway или Разработка системы распределенных вычислений с нуля
Async Gateway или Разработка системы распределенных вычислений с нуляAsync Gateway или Разработка системы распределенных вычислений с нуля
Async Gateway или Разработка системы распределенных вычислений с нуля
 
API Asynchrones en Java 8
API Asynchrones en Java 8API Asynchrones en Java 8
API Asynchrones en Java 8
 
Алексей Николаенков, Devexperts
Алексей Николаенков, DevexpertsАлексей Николаенков, Devexperts
Алексей Николаенков, Devexperts
 
Amazon cloud – готовим вместе
Amazon cloud – готовим вместеAmazon cloud – готовим вместе
Amazon cloud – готовим вместе
 
Hazelcast for Terracotta Users
Hazelcast for Terracotta UsersHazelcast for Terracotta Users
Hazelcast for Terracotta Users
 
Code review at large scale
Code review at large scaleCode review at large scale
Code review at large scale
 
ЖК Зорге 9
ЖК Зорге 9ЖК Зорге 9
ЖК Зорге 9
 

Semelhante a 50 new things we can do with Java 8

AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokusHamletDRC
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionPaulo Morgado
 
Java 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR BeneluxJava 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR Beneluxyohanbeschi
 
JSR 310. New Date API in Java 8
JSR 310. New Date API in Java 8JSR 310. New Date API in Java 8
JSR 310. New Date API in Java 8Serhii Kartashov
 
Unity 2018からのハイパフォーマンスな機能紹介
Unity 2018からのハイパフォーマンスな機能紹介Unity 2018からのハイパフォーマンスな機能紹介
Unity 2018からのハイパフォーマンスな機能紹介dena_genom
 
What did you miss in Java from 9-13?
What did you miss in Java from 9-13?What did you miss in Java from 9-13?
What did you miss in Java from 9-13?relix1988
 
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel ZikmundKarel Zikmund
 
Androidの本当にあった怖い話
Androidの本当にあった怖い話Androidの本当にあった怖い話
Androidの本当にあった怖い話Yusuke Yamamoto
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.David Gómez García
 
#SPUG - Legacy applications
#SPUG - Legacy applications#SPUG - Legacy applications
#SPUG - Legacy applicationsPiotr Pasich
 
Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Paulo Morgado
 
Desafios do Profissionalismo Ágil
Desafios do Profissionalismo ÁgilDesafios do Profissionalismo Ágil
Desafios do Profissionalismo ÁgilVictor Hugo Germano
 
OOP and FP: become a better programmer - Simone Bordet, Mario Fusco - Codemot...
OOP and FP: become a better programmer - Simone Bordet, Mario Fusco - Codemot...OOP and FP: become a better programmer - Simone Bordet, Mario Fusco - Codemot...
OOP and FP: become a better programmer - Simone Bordet, Mario Fusco - Codemot...Codemotion
 
OOP and FP - Become a Better Programmer
OOP and FP - Become a Better ProgrammerOOP and FP - Become a Better Programmer
OOP and FP - Become a Better ProgrammerMario Fusco
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges✅ William Pinaud
 

Semelhante a 50 new things we can do with Java 8 (20)

AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf Edition
 
Java 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR BeneluxJava 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR Benelux
 
Java 8 Date and Time API
Java 8 Date and Time APIJava 8 Date and Time API
Java 8 Date and Time API
 
JSR 310. New Date API in Java 8
JSR 310. New Date API in Java 8JSR 310. New Date API in Java 8
JSR 310. New Date API in Java 8
 
Unity 2018からのハイパフォーマンスな機能紹介
Unity 2018からのハイパフォーマンスな機能紹介Unity 2018からのハイパフォーマンスな機能紹介
Unity 2018からのハイパフォーマンスな機能紹介
 
Functional C++
Functional C++Functional C++
Functional C++
 
What did you miss in Java from 9-13?
What did you miss in Java from 9-13?What did you miss in Java from 9-13?
What did you miss in Java from 9-13?
 
Fantom and Tales
Fantom and TalesFantom and Tales
Fantom and Tales
 
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
 
Androidの本当にあった怖い話
Androidの本当にあった怖い話Androidの本当にあった怖い話
Androidの本当にあった怖い話
 
Current State of Coroutines
Current State of CoroutinesCurrent State of Coroutines
Current State of Coroutines
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
 
#SPUG - Legacy applications
#SPUG - Legacy applications#SPUG - Legacy applications
#SPUG - Legacy applications
 
Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#
 
15. DateTime API.ppt
15. DateTime API.ppt15. DateTime API.ppt
15. DateTime API.ppt
 
Desafios do Profissionalismo Ágil
Desafios do Profissionalismo ÁgilDesafios do Profissionalismo Ágil
Desafios do Profissionalismo Ágil
 
OOP and FP: become a better programmer - Simone Bordet, Mario Fusco - Codemot...
OOP and FP: become a better programmer - Simone Bordet, Mario Fusco - Codemot...OOP and FP: become a better programmer - Simone Bordet, Mario Fusco - Codemot...
OOP and FP: become a better programmer - Simone Bordet, Mario Fusco - Codemot...
 
OOP and FP - Become a Better Programmer
OOP and FP - Become a Better ProgrammerOOP and FP - Become a Better Programmer
OOP and FP - Become a Better Programmer
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
 

Mais de José Paumard

Loom Virtual Threads in the JDK 19
Loom Virtual Threads in the JDK 19Loom Virtual Threads in the JDK 19
Loom Virtual Threads in the JDK 19José Paumard
 
From Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdfFrom Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdfJosé Paumard
 
The Future of Java: Records, Sealed Classes and Pattern Matching
The Future of Java: Records, Sealed Classes and Pattern MatchingThe Future of Java: Records, Sealed Classes and Pattern Matching
The Future of Java: Records, Sealed Classes and Pattern MatchingJosé Paumard
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKJosé Paumard
 
Designing functional and fluent API: application to some GoF patterns
Designing functional and fluent API: application to some GoF patternsDesigning functional and fluent API: application to some GoF patterns
Designing functional and fluent API: application to some GoF patternsJosé Paumard
 
The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of FlatteryJosé Paumard
 
The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of FlatteryJosé Paumard
 
Designing functional and fluent API: example of the Visitor Pattern
Designing functional and fluent API: example of the Visitor PatternDesigning functional and fluent API: example of the Visitor Pattern
Designing functional and fluent API: example of the Visitor PatternJosé Paumard
 
Construire son JDK en 10 étapes
Construire son JDK en 10 étapesConstruire son JDK en 10 étapes
Construire son JDK en 10 étapesJosé Paumard
 
Java Keeps Throttling Up!
Java Keeps Throttling Up!Java Keeps Throttling Up!
Java Keeps Throttling Up!José Paumard
 
Asynchronous Systems with Fn Flow
Asynchronous Systems with Fn FlowAsynchronous Systems with Fn Flow
Asynchronous Systems with Fn FlowJosé Paumard
 
JAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJosé Paumard
 
Collectors in the Wild
Collectors in the WildCollectors in the Wild
Collectors in the WildJosé Paumard
 
JAX RS and CDI bike the reactive bridge
JAX RS and CDI bike the reactive bridgeJAX RS and CDI bike the reactive bridge
JAX RS and CDI bike the reactive bridgeJosé Paumard
 
L'API Collector dans tous ses états
L'API Collector dans tous ses étatsL'API Collector dans tous ses états
L'API Collector dans tous ses étatsJosé Paumard
 
Java 8 Streams and Rx Java Comparison
Java 8 Streams and Rx Java ComparisonJava 8 Streams and Rx Java Comparison
Java 8 Streams and Rx Java ComparisonJosé Paumard
 

Mais de José Paumard (17)

Loom Virtual Threads in the JDK 19
Loom Virtual Threads in the JDK 19Loom Virtual Threads in the JDK 19
Loom Virtual Threads in the JDK 19
 
From Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdfFrom Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdf
 
The Future of Java: Records, Sealed Classes and Pattern Matching
The Future of Java: Records, Sealed Classes and Pattern MatchingThe Future of Java: Records, Sealed Classes and Pattern Matching
The Future of Java: Records, Sealed Classes and Pattern Matching
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
 
Designing functional and fluent API: application to some GoF patterns
Designing functional and fluent API: application to some GoF patternsDesigning functional and fluent API: application to some GoF patterns
Designing functional and fluent API: application to some GoF patterns
 
The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of Flattery
 
The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of Flattery
 
Designing functional and fluent API: example of the Visitor Pattern
Designing functional and fluent API: example of the Visitor PatternDesigning functional and fluent API: example of the Visitor Pattern
Designing functional and fluent API: example of the Visitor Pattern
 
Construire son JDK en 10 étapes
Construire son JDK en 10 étapesConstruire son JDK en 10 étapes
Construire son JDK en 10 étapes
 
Java Keeps Throttling Up!
Java Keeps Throttling Up!Java Keeps Throttling Up!
Java Keeps Throttling Up!
 
Asynchronous Systems with Fn Flow
Asynchronous Systems with Fn FlowAsynchronous Systems with Fn Flow
Asynchronous Systems with Fn Flow
 
JAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) Bridge
 
Collectors in the Wild
Collectors in the WildCollectors in the Wild
Collectors in the Wild
 
Streams in the wild
Streams in the wildStreams in the wild
Streams in the wild
 
JAX RS and CDI bike the reactive bridge
JAX RS and CDI bike the reactive bridgeJAX RS and CDI bike the reactive bridge
JAX RS and CDI bike the reactive bridge
 
L'API Collector dans tous ses états
L'API Collector dans tous ses étatsL'API Collector dans tous ses états
L'API Collector dans tous ses états
 
Java 8 Streams and Rx Java Comparison
Java 8 Streams and Rx Java ComparisonJava 8 Streams and Rx Java Comparison
Java 8 Streams and Rx Java Comparison
 

Último

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 

Último (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 

50 new things we can do with Java 8