SlideShare a Scribd company logo
1 of 28
Dori Waldman

Lambda Expressions

CompletableFuture

Method References

Functional Interfaces

Default Methods

Streams

Optional Class

New Date/Time API
...
Agenda
Functional programming: “Lambda allow us to treat functionality as a method
argument (passing functions around)”
Syntax:
1) Infers syntax : return / type / {} / ()
Integer sub = (a, b) → a – b; // no need to write (int a, int b) -> { return a * b; }
Arrays.asList( "a", "b").forEach( e → System.out.println( e ) );
// no need to write ((String)e) → ...
Lambda (→)
Lambda (→)
2) Function as parameter
Lambda (→)
3) Eliminates the need of anonymous class
4) Make code more immutable
Lambda (→) , the bad parts
https://dzone.com/articles/whats-wrong-java-8-part-ii - be aware of auto-boxing
System.out.println((x -> x / 100 * (100 + 10)).apply(100)); // java does not know type of X
System.out.println((Integer x) -> x / 100 * 100 + 10).apply(100)); // → is a function , java does
not know Function type
System.out.println(((Function<Integer, Integer>) x -> x / 100 * 100 + 10).apply(100));
* Auto-boxing means automatic convert between primitive and object
To allow functions to take lambdas as arguments, Java 8 use “functional interface”
which is an interface with has only one abstract method (like Runnable)
Functional Interface
Interface (Default & Static method)
Default methods make interfaces similar to scala trait,
Interface must implement the default method each implement will inherit it
java.util.function contains 43 methods like:
BiFunction<T,U,R>
Represents a function that accepts two arguments and produces a result.
http://www.tutorialspoint.com/java8/java8_functional_interfaces.htm
Predicate<T> // represent a function that return true/false
public void calculate(List<Integer> list, Predicate<Integer> predicate) {
for(Integer n: list) {
if(predicate.test(n)) { //test evaluate predicate on argument
System.out.println(n + " ");
}
}
}
calculate(list, n-> n%2 == 0 );
Function API
http://howtodoinjava.com/java-8/how-to-use-predicate-in-java-8/
Call methods by their names
allows us to reference constructors or methods without executing them
You can’t pass arguments to methods Reference
List names = ArrayList::new;
names.add(“a”);
names.add(“b”);
names.forEach(System.out::println);
Car carInstance = Car.create( Car::new );
Car::collide;
carInstance::drive;
Method reference (::)
Method reference vs Lamdba
Curring
function that returns a function instead of a result.
Java 8 brings new abilities to work with Collections,Arrays, or I/O resources as
input source
Stream API offers easy filtering, aggregation, and mapping actions
Operations can return stream (pipelined) or result (like collect())
parallelStream : leverage multicore architecture without the need to write any
specific code for it (using ForkJoinThreadPool)
http://zeroturnaround.com/rebellabs/java-parallel-streams-are-bad-for-your-health/
https://dzone.com/articles/whats-wrong-java-8-part-iii
Stream
Stream() / filter() / map() return new stream object
Stream() convert collection to stream
Stream
collect() allows us to collect the results of a stream
Collectors are used to combine the stream result:
List<String>strings = Arrays.asList("a", "", "b", "");
List<String> filtered = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList());
String mergedString = strings.stream().filter(string -> string.isEmpty()).collect(Collectors.joining(", "));
List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);
IntSummaryStatistics stats = numbers.stream().mapToInt((x) -> x).summaryStatistics();
stats.getMax();
stats.getSum();
stats.getAverage();
Stream – Collectors & Aggregation
Stream – yet another example
Parallel Stream
CompletableFuture
Java 7 has no interface to get the async task result in the future , there is a way to get
the result outside of the future and when its done perform another action
Java 8 added Completefuture<T> interface
CompletableFuture
Optional is a container: it can hold a value of some type T or just be null.
It replace null checking and can avoid NullPointerException.
Integer value1 = null;
Integer value2 = new Integer(10);
Optional<Integer> a = Optional.ofNullable(value1); //represent null
Optional<Integer> b = Optional.of(value2);
Public Integer sum(Optional<Integer> a, Optional<Integer> b){
a.isPresent(); // false
Integer value1 = a.orElse(new Integer(5)); // 5
a.orElseGet( () -> 77 ) // instead of parameter it accept a method
Integer value2 = b.get(); // 10
return value1 + value2; // 15
}
What makes Optional truly appealing are methods such as ifPresent() and
orElseThrow() along with map() and filter() which all accept lambda
expressions ~ scala monad
Optional Class
java.util.Date & Calendar are not thread safe, developer need to manage timezone issues
popular solution JodaTime is 3#party not part of the Java api.
Java 8 has 2 implementation : Local / Zoned (which support timezone)
LocalDateTime currentTime = LocalDateTime.now(); //2014-12-10
LocalDate.now(Clock.systemUTC()) // Clock object provide access to datetime using timezone
// Clock can be used instead of System.currentTimeMillis() and TimeZone.getDefault().
LocalDate nextWeek = currentTime.plus(1, ChronoUnit.WEEKS); //2014-12-17
Period period = Period.between(currentTime, nextWeek);
Duration.between( currentTime, nextWeek ).toDays();
LocalDate nextTuesday = date1.with(TemporalAdjusters.next(DayOfWeek.TUESDAY)); //2014-12-16
LocalDate date = LocalDate.of(2014, Month.DECEMBER, 12);
ZonedDateTime date1 =
ZonedDateTime.parse("2007-12-03T10:15:30+05:30[Asia/Karachi]");
DateTime (immutable)
DateTime
Concurrency
how-longadder-performs-better-than-atomiclong
Atomic are used to increment a variable across threads, faster than locks.
Java 8 added adders and accumulators which to improve Atomic
Concurrency
JVM options -XX:PermSize and –XX:MaxPermSize have been replaced by
-XX:MetaSpaceSize and -XX:MaxMetaspaceSize respectively
JVM
GC1
Built in base64 encoder/decoder
Invoke JAVA from JS and JS from JAVA using Nashorn (replace Rhino)
Annotate local variables, generic types ...
Repeating annotation
Extra
“As a Scala and Java developer, I am not even slightly tempted to replace Scala as my main language for my next project with Java 8.
If I'm forced to write Java, it might better be Java 8,
but if I have a choice, there are so many things (as the OP correctly states) that make Scala compelling for me beyond Lambdas
that just adding that feature to Java doesn't really mean anything to me.
Ruby has Lambdas, so does Python and JavaScript, Dart and I'm sure any other modern language.
I like Scala because of so many other things other than lambdas that a single comment is not enough.
But to name a few (some were referenced by the OP)
Everything is an expression,
For comprehensions (especially with multiple futures, resolving the callback triangle of death in a beautiful syntax IMHO),
Implicit conversions,
Case classes,
Pattern Matching,
Tuples,
The fact that everything has equals and hashcode already correctly implemented (so I can put a tuple, or even an Array as a key in a map),
string interpolation,
multiline string,
default parameters,
named parameters,
built in dependency injection,
most complex yet most powerful type system in any language I know of, type inference (not as good as Haskell, but better than the non existent in Java).
The fact I always get the right type returned from a set of "monadic" actions thanks to infamous things like CanBuildFrom (which are pure genius).
Let's not forget pass by name arguments and the ability to construct a DSL. Extractors (via pattern matching). And many more.
I think Scala is here to stay, at least for Scala developers,
I am 100% sure you will not find a single Scala developer that will say: "Java 8 got lambdas? great, goodbye scala forever!".
Only reason I can think of is compile time and binary compatibility.
If we ignore those two, all I can say is that this just proves how Scala is in the right direction
(since Java 8 lambdas and default interface methods and steams are so clearly influenced)
I do wish however that Scala will improve Java 8 interoperability, e.g. support functional interfaces the same way.
and add new implicit conversions to Java 8 collections as well as take advantage to improvements in the JVM.
I will replace Scala as soon as I find a language that gives me what Scala does and does it better.
So far I didn't find such a language (examined Haskell, Clojure, Go, Kotlin, Ceylon, Dart, TypeScript, Rust, Julia, D and Nimrod, Ruby Python, JavaScript and C#,
some of them were very promising but since I need a JVM language, and preferably a statically typed one, it narrowed down the choices pretty quickly)
Java 8 is by far not even close, sorry. Great improvement, I'm very happy for Java developers that will get "permission" to use it (might be easier to adopt than Scala in an enterprise)
but this is not a reason for a Scala shop to consider moving back to Java.”
So should I leave Scala ?
https://news.ycombinator.com/item?id=7478367
Java has taken "Scala - the good parts"“martin odersky improve Java again (Generics)”

https://www.toptal.com/java/why-you-need-to-upgrade-to-java-8-already

http://www.javaworld.com/article/2078836/java-se/love-and-hate-for-java-8.html

http://allegro.tech/2014/12/How-to-migrate-to-Java-8.html

https://www.javacodegeeks.com/2014/05/java-8-features-tutorial.html

http://zeroturnaround.com/rebellabs/java-parallel-streams-are-bad-for-your-health/

https://dzone.com/articles/whats-wrong-java-8-currying-vs

https://dzone.com/articles/whats-wrong-java-8-part-ii

https://dzone.com/articles/whats-wrong-java-8-part-iii

https://dzone.com/articles/whats-wrong-java-8-part-iv

https://dzone.com/articles/whats-wrong-java-8-part-v

https://dzone.com/articles/whats-wrong-java-8-part-vi

https://dzone.com/articles/whats-wrong-java-8-part-vii

http://www.tutorialspoint.com/java8/

http://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html

http://winterbe.com/posts/2015/05/22/java8-concurrency-tutorial-atomic-concurrent-map-examples/

http://www.concretepage.com/java/jdk-8/function-apply-in-java-8
Links

More Related Content

What's hot

Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...Dan Halperin
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaRick Warren
 
HBase RowKey design for Akka Persistence
HBase RowKey design for Akka PersistenceHBase RowKey design for Akka Persistence
HBase RowKey design for Akka PersistenceKonrad Malawski
 
Spark Summit EU talk by Nimbus Goehausen
Spark Summit EU talk by Nimbus GoehausenSpark Summit EU talk by Nimbus Goehausen
Spark Summit EU talk by Nimbus GoehausenSpark Summit
 
Real-Time Analytics with Kafka, Cassandra and Storm
Real-Time Analytics with Kafka, Cassandra and StormReal-Time Analytics with Kafka, Cassandra and Storm
Real-Time Analytics with Kafka, Cassandra and StormJohn Georgiadis
 
Harnessing the power of YARN with Apache Twill
Harnessing the power of YARN with Apache TwillHarnessing the power of YARN with Apache Twill
Harnessing the power of YARN with Apache TwillTerence Yim
 
Rxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJavaRxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJavaKros Huang
 
Developing Java Streaming Applications with Apache Storm
Developing Java Streaming Applications with Apache StormDeveloping Java Streaming Applications with Apache Storm
Developing Java Streaming Applications with Apache StormLester Martin
 
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...Reactivesummit
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 
Distributed Real-Time Stream Processing: Why and How 2.0
Distributed Real-Time Stream Processing:  Why and How 2.0Distributed Real-Time Stream Processing:  Why and How 2.0
Distributed Real-Time Stream Processing: Why and How 2.0Petr Zapletal
 
Unit testing of spark applications
Unit testing of spark applicationsUnit testing of spark applications
Unit testing of spark applicationsKnoldus Inc.
 
A dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenarioA dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenarioGioia Ballin
 
Distributed real time stream processing- why and how
Distributed real time stream processing- why and howDistributed real time stream processing- why and how
Distributed real time stream processing- why and howPetr Zapletal
 
Deep Dive into Stateful Stream Processing in Structured Streaming with Tathag...
Deep Dive into Stateful Stream Processing in Structured Streaming with Tathag...Deep Dive into Stateful Stream Processing in Structured Streaming with Tathag...
Deep Dive into Stateful Stream Processing in Structured Streaming with Tathag...Databricks
 
RxJava 2.0 介紹
RxJava 2.0 介紹RxJava 2.0 介紹
RxJava 2.0 介紹Kros Huang
 
Meetup cassandra sfo_jdbc
Meetup cassandra sfo_jdbcMeetup cassandra sfo_jdbc
Meetup cassandra sfo_jdbczznate
 
Realtime Statistics based on Apache Storm and RocketMQ
Realtime Statistics based on Apache Storm and RocketMQRealtime Statistics based on Apache Storm and RocketMQ
Realtime Statistics based on Apache Storm and RocketMQXin Wang
 
Spark summit2014 techtalk - testing spark
Spark summit2014 techtalk - testing sparkSpark summit2014 techtalk - testing spark
Spark summit2014 techtalk - testing sparkAnu Shetty
 
Building large-scale analytics platform with Storm, Kafka and Cassandra - NYC...
Building large-scale analytics platform with Storm, Kafka and Cassandra - NYC...Building large-scale analytics platform with Storm, Kafka and Cassandra - NYC...
Building large-scale analytics platform with Storm, Kafka and Cassandra - NYC...Alexey Kharlamov
 

What's hot (20)

Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 
HBase RowKey design for Akka Persistence
HBase RowKey design for Akka PersistenceHBase RowKey design for Akka Persistence
HBase RowKey design for Akka Persistence
 
Spark Summit EU talk by Nimbus Goehausen
Spark Summit EU talk by Nimbus GoehausenSpark Summit EU talk by Nimbus Goehausen
Spark Summit EU talk by Nimbus Goehausen
 
Real-Time Analytics with Kafka, Cassandra and Storm
Real-Time Analytics with Kafka, Cassandra and StormReal-Time Analytics with Kafka, Cassandra and Storm
Real-Time Analytics with Kafka, Cassandra and Storm
 
Harnessing the power of YARN with Apache Twill
Harnessing the power of YARN with Apache TwillHarnessing the power of YARN with Apache Twill
Harnessing the power of YARN with Apache Twill
 
Rxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJavaRxjava 介紹與 Android 中的 RxJava
Rxjava 介紹與 Android 中的 RxJava
 
Developing Java Streaming Applications with Apache Storm
Developing Java Streaming Applications with Apache StormDeveloping Java Streaming Applications with Apache Storm
Developing Java Streaming Applications with Apache Storm
 
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Distributed Real-Time Stream Processing: Why and How 2.0
Distributed Real-Time Stream Processing:  Why and How 2.0Distributed Real-Time Stream Processing:  Why and How 2.0
Distributed Real-Time Stream Processing: Why and How 2.0
 
Unit testing of spark applications
Unit testing of spark applicationsUnit testing of spark applications
Unit testing of spark applications
 
A dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenarioA dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenario
 
Distributed real time stream processing- why and how
Distributed real time stream processing- why and howDistributed real time stream processing- why and how
Distributed real time stream processing- why and how
 
Deep Dive into Stateful Stream Processing in Structured Streaming with Tathag...
Deep Dive into Stateful Stream Processing in Structured Streaming with Tathag...Deep Dive into Stateful Stream Processing in Structured Streaming with Tathag...
Deep Dive into Stateful Stream Processing in Structured Streaming with Tathag...
 
RxJava 2.0 介紹
RxJava 2.0 介紹RxJava 2.0 介紹
RxJava 2.0 介紹
 
Meetup cassandra sfo_jdbc
Meetup cassandra sfo_jdbcMeetup cassandra sfo_jdbc
Meetup cassandra sfo_jdbc
 
Realtime Statistics based on Apache Storm and RocketMQ
Realtime Statistics based on Apache Storm and RocketMQRealtime Statistics based on Apache Storm and RocketMQ
Realtime Statistics based on Apache Storm and RocketMQ
 
Spark summit2014 techtalk - testing spark
Spark summit2014 techtalk - testing sparkSpark summit2014 techtalk - testing spark
Spark summit2014 techtalk - testing spark
 
Building large-scale analytics platform with Storm, Kafka and Cassandra - NYC...
Building large-scale analytics platform with Storm, Kafka and Cassandra - NYC...Building large-scale analytics platform with Storm, Kafka and Cassandra - NYC...
Building large-scale analytics platform with Storm, Kafka and Cassandra - NYC...
 

Viewers also liked

Spark streaming with kafka
Spark streaming with kafkaSpark streaming with kafka
Spark streaming with kafkaDori Waldman
 
Dori waldman android _course_2
Dori waldman android _course_2Dori waldman android _course_2
Dori waldman android _course_2Dori Waldman
 
Dori waldman android _course
Dori waldman android _courseDori waldman android _course
Dori waldman android _courseDori Waldman
 
What's new in Java 8
What's new in Java 8What's new in Java 8
What's new in Java 8jclingan
 
TDC 2015 - Java: from old school to modern art!
TDC 2015 - Java: from old school to modern art!TDC 2015 - Java: from old school to modern art!
TDC 2015 - Java: from old school to modern art!Marcos Ferreira
 
from old java to java8 - KanJava Edition
from old java to java8 - KanJava Editionfrom old java to java8 - KanJava Edition
from old java to java8 - KanJava Edition心 谷本
 
50 new things you can do with java 8
50 new things you can do with java 850 new things you can do with java 8
50 new things you can do with java 8José Paumard
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 
Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8AppDynamics
 
Java 8, Streams & Collectors, patterns, performances and parallelization
Java 8, Streams & Collectors, patterns, performances and parallelizationJava 8, Streams & Collectors, patterns, performances and parallelization
Java 8, Streams & Collectors, patterns, performances and parallelizationJosé Paumard
 

Viewers also liked (15)

Spark streaming with kafka
Spark streaming with kafkaSpark streaming with kafka
Spark streaming with kafka
 
Dori waldman android _course_2
Dori waldman android _course_2Dori waldman android _course_2
Dori waldman android _course_2
 
Dori waldman android _course
Dori waldman android _courseDori waldman android _course
Dori waldman android _course
 
What's new in Java 8
What's new in Java 8What's new in Java 8
What's new in Java 8
 
TDC 2015 - Java: from old school to modern art!
TDC 2015 - Java: from old school to modern art!TDC 2015 - Java: from old school to modern art!
TDC 2015 - Java: from old school to modern art!
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
Java 8: the good parts!
Java 8: the good parts!Java 8: the good parts!
Java 8: the good parts!
 
from old java to java8 - KanJava Edition
from old java to java8 - KanJava Editionfrom old java to java8 - KanJava Edition
from old java to java8 - KanJava Edition
 
50 new things you can do with java 8
50 new things you can do with java 850 new things you can do with java 8
50 new things you can do with java 8
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8
 
Java 8, Streams & Collectors, patterns, performances and parallelization
Java 8, Streams & Collectors, patterns, performances and parallelizationJava 8, Streams & Collectors, patterns, performances and parallelization
Java 8, Streams & Collectors, patterns, performances and parallelization
 
Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
 
java 8
java 8java 8
java 8
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 

Similar to whats new in java 8

Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
New Features of JAVA SE8
New Features of JAVA SE8New Features of JAVA SE8
New Features of JAVA SE8Dinesh Pathak
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsEmiel Paasschens
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8Martin Toshev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8icarter09
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014Nayden Gochev
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Ganesh Samarthyam
 
Gude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerGude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerApache Traffic Server
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentationVan Huong
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 itiAhmed mar3y
 
Xebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_finalXebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_finalUrs Peter
 
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesAutomatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesRaffi Khatchadourian
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 

Similar to whats new in java 8 (20)

Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Colloquium Report
Colloquium ReportColloquium Report
Colloquium Report
 
New Features of JAVA SE8
New Features of JAVA SE8New Features of JAVA SE8
New Features of JAVA SE8
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Software Uni Conf October 2014
Software Uni Conf October 2014Software Uni Conf October 2014
Software Uni Conf October 2014
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
 
Gude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerGude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic Server
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
Xebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_finalXebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_final
 
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesAutomatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to Interfaces
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Wien15 java8
Wien15 java8Wien15 java8
Wien15 java8
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
 

More from Dori Waldman

iceberg introduction.pptx
iceberg introduction.pptxiceberg introduction.pptx
iceberg introduction.pptxDori Waldman
 
spark stream - kafka - the right way
spark stream - kafka - the right way spark stream - kafka - the right way
spark stream - kafka - the right way Dori Waldman
 
Druid meetup @walkme
Druid meetup @walkmeDruid meetup @walkme
Druid meetup @walkmeDori Waldman
 
Machine Learning and Deep Learning 4 dummies
Machine Learning and Deep Learning 4 dummies Machine Learning and Deep Learning 4 dummies
Machine Learning and Deep Learning 4 dummies Dori Waldman
 
Big data should be simple
Big data should be simpleBig data should be simple
Big data should be simpleDori Waldman
 

More from Dori Waldman (8)

openai.pptx
openai.pptxopenai.pptx
openai.pptx
 
iceberg introduction.pptx
iceberg introduction.pptxiceberg introduction.pptx
iceberg introduction.pptx
 
spark stream - kafka - the right way
spark stream - kafka - the right way spark stream - kafka - the right way
spark stream - kafka - the right way
 
Druid meetup @walkme
Druid meetup @walkmeDruid meetup @walkme
Druid meetup @walkme
 
Machine Learning and Deep Learning 4 dummies
Machine Learning and Deep Learning 4 dummies Machine Learning and Deep Learning 4 dummies
Machine Learning and Deep Learning 4 dummies
 
Druid
DruidDruid
Druid
 
Memcached
MemcachedMemcached
Memcached
 
Big data should be simple
Big data should be simpleBig data should be simple
Big data should be simple
 

Recently uploaded

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

whats new in java 8

  • 2.  Lambda Expressions  CompletableFuture  Method References  Functional Interfaces  Default Methods  Streams  Optional Class  New Date/Time API ... Agenda
  • 3. Functional programming: “Lambda allow us to treat functionality as a method argument (passing functions around)” Syntax: 1) Infers syntax : return / type / {} / () Integer sub = (a, b) → a – b; // no need to write (int a, int b) -> { return a * b; } Arrays.asList( "a", "b").forEach( e → System.out.println( e ) ); // no need to write ((String)e) → ... Lambda (→)
  • 5. Lambda (→) 3) Eliminates the need of anonymous class 4) Make code more immutable
  • 6. Lambda (→) , the bad parts https://dzone.com/articles/whats-wrong-java-8-part-ii - be aware of auto-boxing System.out.println((x -> x / 100 * (100 + 10)).apply(100)); // java does not know type of X System.out.println((Integer x) -> x / 100 * 100 + 10).apply(100)); // → is a function , java does not know Function type System.out.println(((Function<Integer, Integer>) x -> x / 100 * 100 + 10).apply(100)); * Auto-boxing means automatic convert between primitive and object
  • 7. To allow functions to take lambdas as arguments, Java 8 use “functional interface” which is an interface with has only one abstract method (like Runnable) Functional Interface
  • 8. Interface (Default & Static method) Default methods make interfaces similar to scala trait, Interface must implement the default method each implement will inherit it
  • 9. java.util.function contains 43 methods like: BiFunction<T,U,R> Represents a function that accepts two arguments and produces a result. http://www.tutorialspoint.com/java8/java8_functional_interfaces.htm Predicate<T> // represent a function that return true/false public void calculate(List<Integer> list, Predicate<Integer> predicate) { for(Integer n: list) { if(predicate.test(n)) { //test evaluate predicate on argument System.out.println(n + " "); } } } calculate(list, n-> n%2 == 0 ); Function API http://howtodoinjava.com/java-8/how-to-use-predicate-in-java-8/
  • 10. Call methods by their names allows us to reference constructors or methods without executing them You can’t pass arguments to methods Reference List names = ArrayList::new; names.add(“a”); names.add(“b”); names.forEach(System.out::println); Car carInstance = Car.create( Car::new ); Car::collide; carInstance::drive; Method reference (::)
  • 12. Curring function that returns a function instead of a result.
  • 13. Java 8 brings new abilities to work with Collections,Arrays, or I/O resources as input source Stream API offers easy filtering, aggregation, and mapping actions Operations can return stream (pipelined) or result (like collect()) parallelStream : leverage multicore architecture without the need to write any specific code for it (using ForkJoinThreadPool) http://zeroturnaround.com/rebellabs/java-parallel-streams-are-bad-for-your-health/ https://dzone.com/articles/whats-wrong-java-8-part-iii Stream Stream() / filter() / map() return new stream object Stream() convert collection to stream
  • 14. Stream collect() allows us to collect the results of a stream Collectors are used to combine the stream result: List<String>strings = Arrays.asList("a", "", "b", ""); List<String> filtered = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList()); String mergedString = strings.stream().filter(string -> string.isEmpty()).collect(Collectors.joining(", "));
  • 15. List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5); IntSummaryStatistics stats = numbers.stream().mapToInt((x) -> x).summaryStatistics(); stats.getMax(); stats.getSum(); stats.getAverage(); Stream – Collectors & Aggregation
  • 16. Stream – yet another example
  • 18. CompletableFuture Java 7 has no interface to get the async task result in the future , there is a way to get the result outside of the future and when its done perform another action Java 8 added Completefuture<T> interface
  • 20. Optional is a container: it can hold a value of some type T or just be null. It replace null checking and can avoid NullPointerException. Integer value1 = null; Integer value2 = new Integer(10); Optional<Integer> a = Optional.ofNullable(value1); //represent null Optional<Integer> b = Optional.of(value2); Public Integer sum(Optional<Integer> a, Optional<Integer> b){ a.isPresent(); // false Integer value1 = a.orElse(new Integer(5)); // 5 a.orElseGet( () -> 77 ) // instead of parameter it accept a method Integer value2 = b.get(); // 10 return value1 + value2; // 15 } What makes Optional truly appealing are methods such as ifPresent() and orElseThrow() along with map() and filter() which all accept lambda expressions ~ scala monad Optional Class
  • 21. java.util.Date & Calendar are not thread safe, developer need to manage timezone issues popular solution JodaTime is 3#party not part of the Java api. Java 8 has 2 implementation : Local / Zoned (which support timezone) LocalDateTime currentTime = LocalDateTime.now(); //2014-12-10 LocalDate.now(Clock.systemUTC()) // Clock object provide access to datetime using timezone // Clock can be used instead of System.currentTimeMillis() and TimeZone.getDefault(). LocalDate nextWeek = currentTime.plus(1, ChronoUnit.WEEKS); //2014-12-17 Period period = Period.between(currentTime, nextWeek); Duration.between( currentTime, nextWeek ).toDays(); LocalDate nextTuesday = date1.with(TemporalAdjusters.next(DayOfWeek.TUESDAY)); //2014-12-16 LocalDate date = LocalDate.of(2014, Month.DECEMBER, 12); ZonedDateTime date1 = ZonedDateTime.parse("2007-12-03T10:15:30+05:30[Asia/Karachi]"); DateTime (immutable)
  • 23. Concurrency how-longadder-performs-better-than-atomiclong Atomic are used to increment a variable across threads, faster than locks. Java 8 added adders and accumulators which to improve Atomic
  • 25. JVM options -XX:PermSize and –XX:MaxPermSize have been replaced by -XX:MetaSpaceSize and -XX:MaxMetaspaceSize respectively JVM GC1
  • 26. Built in base64 encoder/decoder Invoke JAVA from JS and JS from JAVA using Nashorn (replace Rhino) Annotate local variables, generic types ... Repeating annotation Extra
  • 27. “As a Scala and Java developer, I am not even slightly tempted to replace Scala as my main language for my next project with Java 8. If I'm forced to write Java, it might better be Java 8, but if I have a choice, there are so many things (as the OP correctly states) that make Scala compelling for me beyond Lambdas that just adding that feature to Java doesn't really mean anything to me. Ruby has Lambdas, so does Python and JavaScript, Dart and I'm sure any other modern language. I like Scala because of so many other things other than lambdas that a single comment is not enough. But to name a few (some were referenced by the OP) Everything is an expression, For comprehensions (especially with multiple futures, resolving the callback triangle of death in a beautiful syntax IMHO), Implicit conversions, Case classes, Pattern Matching, Tuples, The fact that everything has equals and hashcode already correctly implemented (so I can put a tuple, or even an Array as a key in a map), string interpolation, multiline string, default parameters, named parameters, built in dependency injection, most complex yet most powerful type system in any language I know of, type inference (not as good as Haskell, but better than the non existent in Java). The fact I always get the right type returned from a set of "monadic" actions thanks to infamous things like CanBuildFrom (which are pure genius). Let's not forget pass by name arguments and the ability to construct a DSL. Extractors (via pattern matching). And many more. I think Scala is here to stay, at least for Scala developers, I am 100% sure you will not find a single Scala developer that will say: "Java 8 got lambdas? great, goodbye scala forever!". Only reason I can think of is compile time and binary compatibility. If we ignore those two, all I can say is that this just proves how Scala is in the right direction (since Java 8 lambdas and default interface methods and steams are so clearly influenced) I do wish however that Scala will improve Java 8 interoperability, e.g. support functional interfaces the same way. and add new implicit conversions to Java 8 collections as well as take advantage to improvements in the JVM. I will replace Scala as soon as I find a language that gives me what Scala does and does it better. So far I didn't find such a language (examined Haskell, Clojure, Go, Kotlin, Ceylon, Dart, TypeScript, Rust, Julia, D and Nimrod, Ruby Python, JavaScript and C#, some of them were very promising but since I need a JVM language, and preferably a statically typed one, it narrowed down the choices pretty quickly) Java 8 is by far not even close, sorry. Great improvement, I'm very happy for Java developers that will get "permission" to use it (might be easier to adopt than Scala in an enterprise) but this is not a reason for a Scala shop to consider moving back to Java.” So should I leave Scala ? https://news.ycombinator.com/item?id=7478367 Java has taken "Scala - the good parts"“martin odersky improve Java again (Generics)”
  • 28.  https://www.toptal.com/java/why-you-need-to-upgrade-to-java-8-already  http://www.javaworld.com/article/2078836/java-se/love-and-hate-for-java-8.html  http://allegro.tech/2014/12/How-to-migrate-to-Java-8.html  https://www.javacodegeeks.com/2014/05/java-8-features-tutorial.html  http://zeroturnaround.com/rebellabs/java-parallel-streams-are-bad-for-your-health/  https://dzone.com/articles/whats-wrong-java-8-currying-vs  https://dzone.com/articles/whats-wrong-java-8-part-ii  https://dzone.com/articles/whats-wrong-java-8-part-iii  https://dzone.com/articles/whats-wrong-java-8-part-iv  https://dzone.com/articles/whats-wrong-java-8-part-v  https://dzone.com/articles/whats-wrong-java-8-part-vi  https://dzone.com/articles/whats-wrong-java-8-part-vii  http://www.tutorialspoint.com/java8/  http://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html  http://winterbe.com/posts/2015/05/22/java8-concurrency-tutorial-atomic-concurrent-map-examples/  http://www.concretepage.com/java/jdk-8/function-apply-in-java-8 Links