getting ready to java 8

Download Getting ready to java 8

Post on 08-Sep-2014

862 views

Category:

Technology

1 download

Embed Size (px)

DESCRIPTION

Сергей Моренец «Новые возможности Java 8», JUG#8 (Днепропетровск)

TRANSCRIPT

  • Getting ready to Java 8 , morenets@mail.ru 24 2014 .
  • About author Works in IT since 2000 11 year of Java SE/EE experience Occupied senior Java developer/Team Lead positions Winner of 2013 JBoss Community Recognition Award. https://www.jboss.org/jbcra
  • About author 6 times speaker at Odessa Java User Group 2 times speaker at JEEConf (2013 and 2014) in Kiev Speaker at Java Breeze 2013 in Odessa Speaker at Java Day 2014 in Minsk Works 2 years as Java lector
  • Java 8 Java 8 has been influenced by Scala much more than how Scala has been influenced by Java Most expected Java release ever
  • JVM-based languages
  • Functional languages
  • Java 8 Code name Kenai Specification JSR-337 Inspired by Scala, Google Guava and Joda Time
  • Java 8 Project Lambda Streams API Functional interfaces Java time Method references Repeatable & time annotations Nashorn Accumulators
  • Java 8 Method Thread.stop() was deprecated in 1998 and rewritten to throw exception in 2014.
  • Schedule 2012/04/26 M1 2012/06/14 M2 2012/08/02 M3 2012/09/13 M4 2012/11/29 M5 2013/01/31 M6 2013/06/13 Feature Complete 2013/09/05 Developer Preview 2014/01/23 Final Release Candidate 2014/03/18 General Availability
  • Java 7
  • Java 7
  • Project Lambda
  • Project Lambda
  • Project Lambda
  • Java 7
  • Project Lambda
  • Project Lambda
  • Java 7
  • Project Lambda
  • Project Lambda
  • Project Lambda Lambdas are not serializable Applied to functional interfaces(with SAM) Cannot use this Not applied to abstract classes(even with SAM)
  • Project Lambda Function Predicate Consumer Supplier BinaryOperator
  • Project Lambda Interface Description Function Function with single argument and result Predicate Tests condition of single argument Consumer Performs operation over single argument Supplier Supplies results BinaryOperator Functions with two arguments and results
  • Lambda vs Anonymous
  • Lambda vs Anonymous
  • Lambda vs Anonymous
  • Lambda vs Anonymous Type Lambdas(ms) Anonymous classes (ms) Execution 364 329 Capturing 316 309 Linkage 354 313
  • Disadvantage
  • Java 7
  • Method reference
  • Method reference
  • Java 7
  • Streams
  • Streams
  • Streams
  • Streams
  • Java 7
  • Streams
  • Streams Sequential Parallel
  • Streams
  • Performance
  • Performance Operation Sequential, sec Parallel,sec Slow operation 1.0 0.4 Quick operation 0.3 2.4
  • Parallelism level
  • Parallelism level Parallel streams use ForkJoinPool to split and combine tasks By default number of threads is equal to number of processors This behavior may be overridden by changing system property java.util.concurrent.ForkJoinPool.common.parallelism
  • Streams
  • Streams
  • Streams
  • Streams
  • Java 7
  • Streams
  • Stream performance
  • Stream performance
  • Iteration test Use case Time(ms) For-each loop 35 forEach(lambda) 79 forEach(consumer) 12
  • Java 7
  • Default methods
  • Default methods
  • Default methods
  • Default methods equals hashCode toString
  • Java 7
  • Java 7
  • Java 7
  • Optional
  • Optional
  • Optional
  • Construct date
  • Java 7
  • Java Time
  • Java Time
  • Java Time
  • Java Time
  • Java 7
  • Java Time
  • Time difference
  • Java Time
  • I/O
  • I/O
  • Encoding
  • Annotations
  • Annotations
  • Repeatable annotations
  • Repeatable annotations
  • Repeatable annotations
  • Annotations Up to Java 7, an annotation was applied to a declaration. A declaration is a part of code that introduces a new name.
  • Annotations Type Method Field Annotation Package Local variable
  • Type annotations
  • Type annotations In Java 8, you can annotate any type use. This can be useful in combination with tools that check for common programming errors
  • Type annotations
  • Type annotations Generic type arguments Superclass and implemented interface Constructor invocations Casting and instanceof Exception specifications Wild card and type bounds
  • Type annotations
  • Nashorn
  • Nashorn Based on Da Vinci Machine Int