JSR 335:                             λProject LambdaFrançois Sarradin -- Xebia
Java Roadmap               337 Java 7     JSR Java 8jul. 2011      aug. 2013                    Java 9                    ...
Project LambdaWhats in it?                    Project                    Lambda                      JSR335               ...
Question     What will be the impact        of Project Lambda        on the Java world?
AnswerLook at Speed Car!
Planning...Presentation + live coding (free to interrupt)● Genesis● Lambda of Java● Project Lambda
...And Then● Debate● Retrospective (agile style!)● Report   ○ Xebia blog   ○ Project Lambda ML
Genesis
More Processors
More ExpressivenessMore Readability   结果 汉字 = new 物().処理();             vs.  fact n = product [1..n]           Is it all C...
FP & Competition    Clojure                   C++          C# / F#               Guava
(Anonymous) Inner ClassA λ SolutionIterables.filter(persons, new Predicate<Person>() {  @Override  public boolean apply(Pe...
(Anonymous) Inner ClassA (better?) λ SolutionIterables.filter(persons, IS_ADULT);Predicate<Person> IS_ADULT   = new Predic...
(Anonymous) Inner Class(Not Really) A λ Solution● "The pain of anonymous inner classes makes us roll  our eyes in the back...
What about Oracle?● "It’s time to add closures to Java" (Mark Reinhold,   12/2009)● "Oracles position is that Java must ev...
Lambda of Java
Here is the λ!(int x, int y) -> { return x + y; }(x, y) -> { return x + y; }(int x, int y) -> x + y        (x, y) -> x + y
Other λ formsx   -> 2 * x() -> 42m   -> {    m.put("France", "Paris");    m.put("UK", "London");    m.put("USA", "Washingt...
Inner Classvs. λ SolutionIterables.filter(persons, new Predicate<Person>() {   @Override   public boolean apply(Person p) ...
Method ReferenceString::valueOf// like: v -> String.valueOf(v)Integer::compare// like: (i1, i2) -> Integer.compare(i1, i2)...
Virtual Extension Method    (VEM)interface Message {    String getMessage() default {      return "Look Ma! Interface with...
VEMMotivation VEM                              eg. Collection API       Help to extend existing APIs       Minimize rewrit...
Collection API Extended  java.util.functions.*  java.util.streams.*  Extension of Iterable, Iterator, Collection, Map, ......
Parallel ComputingAs Easy as 1-2-3?myCollection.stream()   .filter(x -> ...)   .map(x -> ...)   .reduce((x, y) -> ...) // ...
Some kata and demos...
Project Lambda
The Dream Team ;)                    photo: @crazybob
Web SitesJSR335http://jcp.org/en/jsr/detail?id=335OpenJDK 8 Web sitehttp://openjdk.java.net/projects/lambda/
Where to Get Java 8Java SE 8 Early Access (with lambda)http://jdk8.java.net/lambda/Mercurial repohttp://hg.openjdk.java.ne...
Mailing ListsTechnical Discussionmailto:lambda-dev@openjdk.java.nethttp://mail.openjdk.java.net/pipermail/lambda-dev/Libs ...
Around Project LambdaOpenJDK OSX Build (7 & 8)http://code.google.com/p/openjdk-osx-build/                                 ...
Around Project LambdaIn FranceJDK 8: lambdas in Action [FR]http://www.devoxx.                                     O. Crois...
Project Lambdaand the Community● Transparency  ○ Presentations / Publications  ○ Source code available● Early testing by c...
Question● Oneliner, Readability, and Debugability● Java vs. Competitors● What to do for Java 8 to be adopted in  projects?...
Upcoming SlideShare
Loading in …5
×

Java 8 Lambda

1,980 views

Published on

Published in: Technology
  • Be the first to comment

Java 8 Lambda

  1. 1. JSR 335: λProject LambdaFrançois Sarradin -- Xebia
  2. 2. Java Roadmap 337 Java 7 JSR Java 8jul. 2011 aug. 2013 Java 9 ? Modularity Performance ● FP / Parallel comp. Productivity ● Date API improv. ● Type annotation ● Compact profiles ● Nashorn
  3. 3. Project LambdaWhats in it? Project Lambda JSR335 Virtual ExtensionLambda Expression Method Collection API Collection APIFunctional API Parallel Collections Bulk Operations
  4. 4. Question What will be the impact of Project Lambda on the Java world?
  5. 5. AnswerLook at Speed Car!
  6. 6. Planning...Presentation + live coding (free to interrupt)● Genesis● Lambda of Java● Project Lambda
  7. 7. ...And Then● Debate● Retrospective (agile style!)● Report ○ Xebia blog ○ Project Lambda ML
  8. 8. Genesis
  9. 9. More Processors
  10. 10. More ExpressivenessMore Readability 结果 汉字 = new 物().処理(); vs. fact n = product [1..n] Is it all Chinese to you?
  11. 11. FP & Competition Clojure C++ C# / F# Guava
  12. 12. (Anonymous) Inner ClassA λ SolutionIterables.filter(persons, new Predicate<Person>() { @Override public boolean apply(Person person) { return person.getAge() >= 18; }}); // Java + Guava
  13. 13. (Anonymous) Inner ClassA (better?) λ SolutionIterables.filter(persons, IS_ADULT);Predicate<Person> IS_ADULT = new Predicate<Person>() { @Override public boolean apply(Person person) { return person.getAge() >= 18; }}); This is what you really need!
  14. 14. (Anonymous) Inner Class(Not Really) A λ Solution● "The pain of anonymous inner classes makes us roll our eyes in the back of our heads every day." (a wise Oracles client, 01/2011) Average length of Java one-liner is 21 line! @DEVOPS_BORAT - 12/09/2011
  15. 15. What about Oracle?● "It’s time to add closures to Java" (Mark Reinhold, 12/2009)● "Oracles position is that Java must evolve -- carefully, of course -- in order to remain competitive." (Brian Goetz - 08/2011)
  16. 16. Lambda of Java
  17. 17. Here is the λ!(int x, int y) -> { return x + y; }(x, y) -> { return x + y; }(int x, int y) -> x + y (x, y) -> x + y
  18. 18. Other λ formsx -> 2 * x() -> 42m -> { m.put("France", "Paris"); m.put("UK", "London"); m.put("USA", "Washington");}
  19. 19. Inner Classvs. λ SolutionIterables.filter(persons, new Predicate<Person>() { @Override public boolean apply(Person p) { return p.getAge() >= 18; }}); // Java 5-7 + GuavaIterables.filter(persons, // Java 8 + Guava p -> p.getAge() >= 18);
  20. 20. Method ReferenceString::valueOf// like: v -> String.valueOf(v)Integer::compare// like: (i1, i2) -> Integer.compare(i1, i2)Arrays.sort(myInts, Integer::compare)
  21. 21. Virtual Extension Method (VEM)interface Message { String getMessage() default { return "Look Ma! Interface with code!"; }}
  22. 22. VEMMotivation VEM eg. Collection API Help to extend existing APIs Minimize rewrite of existing API implementation eg. Hibernate Collection Implementation
  23. 23. Collection API Extended java.util.functions.* java.util.streams.* Extension of Iterable, Iterator, Collection, Map, ... java.util.Optional
  24. 24. Parallel ComputingAs Easy as 1-2-3?myCollection.stream() .filter(x -> ...) .map(x -> ...) .reduce((x, y) -> ...) // sequentialmyCollection.parallel() .filter(x -> ...) .map(x -> ...) .reduce((x, y) -> ...) // parallel
  25. 25. Some kata and demos...
  26. 26. Project Lambda
  27. 27. The Dream Team ;) photo: @crazybob
  28. 28. Web SitesJSR335http://jcp.org/en/jsr/detail?id=335OpenJDK 8 Web sitehttp://openjdk.java.net/projects/lambda/
  29. 29. Where to Get Java 8Java SE 8 Early Access (with lambda)http://jdk8.java.net/lambda/Mercurial repohttp://hg.openjdk.java.net/lambda/lambda
  30. 30. Mailing ListsTechnical Discussionmailto:lambda-dev@openjdk.java.nethttp://mail.openjdk.java.net/pipermail/lambda-dev/Libs Spec Discussionhttp://mail.openjdk.java.net/pipermail/lambda-libs-spec-<*>/Spec Discussionhttp://mail.openjdk.java.net/pipermail/lambda-spec-<*>/
  31. 31. Around Project LambdaOpenJDK OSX Build (7 & 8)http://code.google.com/p/openjdk-osx-build/ H. GomezJava 8 vs Scala: a FeatureComparisonhttp://www.infoq.com/articles/java-8-vs-scala S. van den Berg U. Peter
  32. 32. Around Project LambdaIn FranceJDK 8: lambdas in Action [FR]http://www.devoxx. O. Croisiercom/display/FR12/JDK+8+demo++lambdas+in+Action G. TardifJava 8 et les Lambda [FR]http://thecodersbreakfast.net/index.php?post/2012/05/30/Java-8-et-les-LambdaCurious about Project Lambda ;)http://blog.xebia.fr/ [FR]http://kerflyn.wordpress.com/ Guess Who?
  33. 33. Project Lambdaand the Community● Transparency ○ Presentations / Publications ○ Source code available● Early testing by community ○ Pre-version available ○ AdoptOpenJDK (http://java. net/projects/adoptopenjdk/pages/AdoptOpenJDK)● Quick feedback ○ ML, Hackdays
  34. 34. Question● Oneliner, Readability, and Debugability● Java vs. Competitors● What to do for Java 8 to be adopted in projects?● Is there a future for Java?

×