Java 8 Features


Functional Interface
  • An Interface that has only one abstract method. 
  • There can be default interface methods.
  • There can be static methods.
  • Current Examples are Runnable / Callable / Comparator
    
    
        public class FunctionalInterfaceEx {
            @FunctionalInterface        
            public interface Functional {
               void method();
            }
    
    
Lambda Expressions
  • Can replace any Functional Interface
    Arrays.asList("a", "b", "d").forEach
    ( e -> {
            System.out.print( e );
            System.out.print( e );
        } 
    ); 


Interface : Default Methods
  • New methods added to existing Interfaces.
  • Implementors need not override these. 
  • Evolves the interface. Current examples : 
    • java.util.Collection  [ stream(), parallelStream(), removeIf()]
    • java.util.Iterable [ forEach() ]
    • java.util.List [ replaceAll() ] 
    private interface DefaultMethods {
        default String notRequired() {
            return "Default implementation";
        }
    }






Interface - Static Methods


     
    public class StaticMethods {
        static List create(Supplier<List> supplier) {
            return supplier.get();
        }
    }
Method Reference
  • Class :: new
  • Class :: static_methods
  • Class :: method
  • instance :: method
Repeating Annotations
@Filter( "filter1" ) 
@Filter( "filter2" ) 
public interface Filterable { 


}

Better Type Inference
     final Value< String > value = new Value<>();

Extended Annotations Support
  • Now, it is possible to annotate mostly everything: local variables, generic types, super-classes and implementing interfaces, even the method’s exceptions declaration
Parameter Names
  • Preserve Parameters names in bytecode.
  • Compile with -parameters argument [ javac Abc -parameters]
Optional - In line Guava library.
  • isPresent(), get(), empty(), ofNullable(T t) 
Streams - java.util.stream - Functional style programming. Collections Processing
  • Collection.stream().filter()
  • Collection.stream().parallel().map(fn).reduce(fn)
  • Collection.stream().mapToDouble(fn).mapToInt(fn)
  • Collection.stream().serial().collect()

New Date Time Library - 
  • JSR 310
  • Influenced by Joda-Time, Immutable 
  • java.time.Clock 
  • java.time.LocalDate 
  • java.time.LocalTime
  • java.time.LocalDateTime
  • java.time.ZonedDateTime
  • java.time.Duration
  • java.time.Instant

Nashorn JavaScript engine

Parallel Arrays
  • parallelSetAll()
  • parallelSort() 

Concurrency
  • New methods added to ConcurrentHashMap & ForkJoinPool
  • New class - java.util.concurrent.locks.StampedLock
Class Dependency Analyser

JVM Features - Permgen is gone
  • JEP 122
  • Replaced with Metaspace - Used native memory for the representation of class metadata

    No comments:

    Post a Comment