Revolution of Java Java 8 – Project Lambda
About Me • Java Developer • Technical Teacher • Blogger @kodcu.com
Java 8 Innovations • Lambda Expressions • Type Inference • Metod References • Collection II • Defender Methods
Functional Interface ? • An Interface includes only one abstract method called as FunctionalInterface • Lambda expressions are converted to a FI’s implementation in Background
Functional Interface Examps. • java.lang.Runnable • java.util.concurrent.Callable • java.nio.file.PathMatcher • java.lang.reflect.InvocationHandler • java.beans.PropertyChangeListener • java.awt.event.ActionListener
Lambda Expressions • Lambda -> (also called Closures), is an expression that reduces vertical boilerplate code. • Concise and Clear code development practice • Interfaces that consist of one more than abstract method, cannot be counterpart of any Lambda expressions. Tip: Exceptions (Defender methods & Object class’ methods)
Focus to Input & Output Runnable r1=new Runnable() { @Override Input public void run() { Output System.out.println(“Hello Uranus."); } };
Example
Lambda Types • 2 type – Single expression // no need “return” • (Integer s) -> ( s*2 ); • |or| (Integer s) -> s*2 ; – Statement Block • (Integer s) -> { return s*2; };
Type Inference (String s) -> { System.out.println(s); }; // equals (s) -> { System.out.println(s); }; // equals s -> { System.out.println(s); };
Type Inference (Integer a, Integer b) -> a + b; // equals (a,b) -> (a+b);
Metod References Runnable r1=new Runnable() { @Override Input public void run() { Output System.out.println(“Hello Uranus."); } };
Metod References
Collection II • Collection II is an attachment to existing Collection Framework. • Supports Jquery like chained methods and Underscore.js like Functional Programming Experience.
Collection II • Existing Collection Framework does not support Concurrent operations in chunked datas. • Cause, existing one applies External Iteration.
Stream <T> Interface • Sequential and Consumable data structure. • The data cannot be fetch again after consumed. • A Stream object can be obtained any data structure in Collection Framework. • Fo.Exm: LinkedList, ArrayList, HashSet.
java.util.function Functional Interfaces • Those special Interfaces support general data operations.
Consumer<T> -> Applying • Consumer gets an input and runs an action. • Does not return any result, only do an action. public void accept(T t);
Predicate<T> -> Filtering • Predicate gets a conditional code and produce -> true || false • In concise, makes filtering. public boolean test(T t);
Function<T, R> -> (Consume & Produce); • Gets any type of input object and Produce an output object. public R apply(T t);
Supplier<T> • Do not get any argument object, only returns instantiation of any object type. public T get();
Bi? BiPredicate<L, R> Compares two inputted object. BiConsumer<T, U> Consumes two type of objects, and produce no result BiFunction<T, U, R> Gets two input object (T , U) and produce a result (R) . . .
Parallel Stream • Any parallelizable operations can run concurrently with Parallel stream object. • Parallel Stream object can be obtain with parallelStream() method from any Streamable data structure.
Lazily & Eagerly Ops. • Some Stream operations can be run Lazly as some Eagerly. Lazy Eager • .filter().map().allMatch(); Lazy Eager • .filter().filter().sorted().forEach();
Lazily & Eagerly • Lazy operations are evaluated together with first encountered Eager operation. • The goal is evaluate chanied operations in one step.
Defender Methods • Before Java 8, Interfaces can contain only abstract methods. • With Java 8, any Interface can contain one or more concrete methods that named default/defender method. • Tip: Default methods do not break nature of F I onctional nterfaces
Defender Methods • Defender Methods, Default Methods, Virtual extension methods • Makes possible usage of concrete methods. • Makes more elastic of Java Inheritance model.
Defender Methods • Defender methods can be re-implemented or inherited by other Interfaces.
? ?? ??? ???? ????? Q/A ???? ??? ?? ?

Java 8 - Project Lambda

  • 1.
    Revolution of Java Java8 – Project Lambda
  • 2.
    About Me • JavaDeveloper • Technical Teacher • Blogger @kodcu.com
  • 3.
    Java 8 Innovations •Lambda Expressions • Type Inference • Metod References • Collection II • Defender Methods
  • 4.
    Functional Interface ? •An Interface includes only one abstract method called as FunctionalInterface • Lambda expressions are converted to a FI’s implementation in Background
  • 5.
    Functional Interface Examps. •java.lang.Runnable • java.util.concurrent.Callable • java.nio.file.PathMatcher • java.lang.reflect.InvocationHandler • java.beans.PropertyChangeListener • java.awt.event.ActionListener
  • 6.
    Lambda Expressions • Lambda-> (also called Closures), is an expression that reduces vertical boilerplate code. • Concise and Clear code development practice • Interfaces that consist of one more than abstract method, cannot be counterpart of any Lambda expressions. Tip: Exceptions (Defender methods & Object class’ methods)
  • 7.
    Focus to Input& Output Runnable r1=new Runnable() { @Override Input public void run() { Output System.out.println(“Hello Uranus."); } };
  • 8.
  • 9.
    Lambda Types • 2type – Single expression // no need “return” • (Integer s) -> ( s*2 ); • |or| (Integer s) -> s*2 ; – Statement Block • (Integer s) -> { return s*2; };
  • 10.
    Type Inference (String s)-> { System.out.println(s); }; // equals (s) -> { System.out.println(s); }; // equals s -> { System.out.println(s); };
  • 11.
    Type Inference (Integer a, Integer b) -> a + b; // equals (a,b) -> (a+b);
  • 12.
    Metod References Runnable r1=newRunnable() { @Override Input public void run() { Output System.out.println(“Hello Uranus."); } };
  • 13.
  • 14.
    Collection II • CollectionII is an attachment to existing Collection Framework. • Supports Jquery like chained methods and Underscore.js like Functional Programming Experience.
  • 15.
    Collection II • ExistingCollection Framework does not support Concurrent operations in chunked datas. • Cause, existing one applies External Iteration.
  • 16.
    Stream <T> Interface •Sequential and Consumable data structure. • The data cannot be fetch again after consumed. • A Stream object can be obtained any data structure in Collection Framework. • Fo.Exm: LinkedList, ArrayList, HashSet.
  • 17.
    java.util.function Functional Interfaces • Those special Interfaces support general data operations.
  • 18.
    Consumer<T> -> Applying •Consumer gets an input and runs an action. • Does not return any result, only do an action. public void accept(T t);
  • 19.
    Predicate<T> -> Filtering •Predicate gets a conditional code and produce -> true || false • In concise, makes filtering. public boolean test(T t);
  • 20.
    Function<T, R> ->(Consume & Produce); • Gets any type of input object and Produce an output object. public R apply(T t);
  • 21.
    Supplier<T> • Do notget any argument object, only returns instantiation of any object type. public T get();
  • 22.
    Bi? BiPredicate<L, R> Compares two inputted object. BiConsumer<T, U> Consumes two type of objects, and produce no result BiFunction<T, U, R> Gets two input object (T , U) and produce a result (R) . . .
  • 23.
    Parallel Stream • Anyparallelizable operations can run concurrently with Parallel stream object. • Parallel Stream object can be obtain with parallelStream() method from any Streamable data structure.
  • 24.
    Lazily & EagerlyOps. • Some Stream operations can be run Lazly as some Eagerly. Lazy Eager • .filter().map().allMatch(); Lazy Eager • .filter().filter().sorted().forEach();
  • 25.
    Lazily & Eagerly •Lazy operations are evaluated together with first encountered Eager operation. • The goal is evaluate chanied operations in one step.
  • 26.
    Defender Methods • BeforeJava 8, Interfaces can contain only abstract methods. • With Java 8, any Interface can contain one or more concrete methods that named default/defender method. • Tip: Default methods do not break nature of F I onctional nterfaces
  • 27.
    Defender Methods • DefenderMethods, Default Methods, Virtual extension methods • Makes possible usage of concrete methods. • Makes more elastic of Java Inheritance model.
  • 28.
    Defender Methods • Defendermethods can be re-implemented or inherited by other Interfaces.
  • 29.
    ? ?? ??? ???? ????? Q/A ???? ??? ?? ?