1 / 14

Introduction to JDK 8

JDK 8. Introduction to JDK 8. Agenda. JDK 8 - Composition. Second part of Plan B. Lambda. Project Jigsaw. Project Coin. ++. ++. Lambda Expressions. An anonymous function with argument list, return type and a body. (argument list) arrow_operator { java_statements }

lilike
Télécharger la présentation

Introduction to JDK 8

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JDK 8 Introduction to JDK 8

  2. Agenda

  3. JDK 8 - Composition Second part of Plan B Lambda Project Jigsaw Project Coin ++ ++

  4. Lambda Expressions An anonymous function with argument list, return type and a body. (argument list) arrow_operator { java_statements} (int, int) -> { x+y} [ ] A definitive epitome programming style dating back to lisp style programming. [ ] Instances of Functional Interfaces. [ ] Lexically scoped programming style.

  5. java.util.function java.lang.FunctionalInterface Function Predicate Consumer IntToLongFunction BooleanSupplier … … A programming paradigm Also called, SAM (Single Abstract Method)

  6. Usage of Lambda Expressions Runnable runnable = () -> { System.out.println("Richard Feynman !!! "); }; runnable.run(); interface java.lang.Runnable { void run(); } interface java.lang.Iterable<T> { java.util.Iterator<T> iterator(); } interfacejava.util.concurrent.Executor{ voidexecute(java.lang.Runnable command); } interfacejava.awt.event.ActionListener{ voidactionPerformed(java.awt.event.ActionEvent e); } Now a functional interface !!!

  7. Internal Iteration Use the forEach List listOfStrings = new ArrayList<String>(); listOfStrings.add("alan"); listOfStrings.add("mathison"); listOfStrings.add("turing"); listOfStrings.forEach(x -> System.out.println(x));

  8. API’s java.util.Optional<T> Optional<Chola> op = Optional.empty(); Optional<Chola> op = Optional.of(new Chola("Karikala")); op.isPresent(); Chola s = op.orElse(new Chola("Raja Raja")); s.getName(); class Chola extends King { String name = "default"; public Chola(String _name) { name = _name; } String getName() { return name; } }

  9. API’s Arrays.asList(stringArray).stream() .filter(s -> s.startsWith("1")) .forEach( s -> { System.out.println(s); }); Arrays.asList(stringArray).parallelStream() .filter(s -> s.startsWith("2")) .forEach( s -> { System.out.println(s); }); Arrays.asList(stringArray).stream() .distinct() .forEach( s -> { System.out.println(s); });

  10. API’s Java.util.StringJoiner StringJoinersj = new StringJoiner("/","<",">"); also, StringJoinersj = new StringJoiner("/"); sj.add("Chera"); sj.add("Chola"); sj.add("Pandya"); sj.add("Dhara"); sj.toString() Output <Chera/Chola/Pandya/Dhara>

  11. Virtual Extension Methods public interface DorothyInterface { default String getName(String name) { return name + "Wizard"; } }

  12. JDK 5 Tiger JDK 6 Mustang JDK 7 Dolphin JDK 8 no code name yet…

  13. “That’s not a mistake” - Mark Reinhold JDK 9 • Multi core scalability • Big data support • Hypervisor Integration • Multi – gigabyte heaps • Project Jigsaw • ...

More Related