Java 8 Features

50 %
50 %
Information about Java 8 Features

Published on May 11, 2014

Author: Soddino



My presentation slides in KMS TechCon 2014, an internal technology event at KMS Technology Vietnam company.

Note: This slide uses lot of animation effects, it's better for you if you download and view it offline.

"Java 8 is one of the most highly anticipated programming language updates in many years. Let me give you an introduction about its new features: Lambda expressions, Method references, Default Methods, Stream API, new JS Engine, new Date/Time API and more..."

© 2013 KMS Technology


JAVA VERSION HISTORY JDK 1.0 (1996) JDK 1.1 (1997) inner classes JavaBeans, JDBC, RMI, reflection, JIT JDK 1.2 (1998) strictfp keyword Swing API, Collections API J2SE 1.3 (2000) JNDI, JPDA JAVA 8 FEATURES J2SE 1.4 (2002) assert keyword Image IO API, Java Web Start J2SE 5.0 (2004) generics, annotations, enum, varagrs Java SE 6 (2006) Performance improvements Scripting Language, Java Compiler API Java SE 7 (2011) try statement, invokedynamic in JVM String in switch, diamond operation

JAVA 8 RELEASE (MAR 18, 2014) Java 7 Lambda Expressions Default Methods Stream API New Date/Time APINashorn Java 8 JAVA 8 FEATURES Others

LAMBDA EXPRESSIONS Java 7 Lambda Expressions Default Methods Stream API New Date/Time APINashorn Java 8 Others JAVA 8 FEATURES

LAMBDA EXPRESSION JAVA 8 FEATURES Functions in Functional Programming Functions in Java  Are arguments, return values from other functions  Are variables and be able stored in data structures  No new types such as function types  Functional Interfaces: are interfaces with exactly one method  java.util.function package Consumer, Function, Predicate, Supplier, BiFunction, DoubleConsumer, IntPredicate, LongSupplier, … Lambda Expressions are functions without declaration of access modifier, return value declaration, and name

LAMBDA EXPRESSION SYNTAX IN JAVA (arguments) -> { body } JAVA 8 FEATURES anonymous inner class lambda expression single-line lambda expression no-parameter lambda expression

METHOD REFERENCES JAVA 8 FEATURES Lambda expressions only call an existing method  Reference to a static method  Reference to an instance method of a particular object  Reference to an constructor // int t1, T t2) // void Consumer.accept(T t) // T IntFunction.apply(int value)

WHY LAMBDA EXPRESSIONS IN JAVA? JAVA 8 FEATURES  Encourage functional programming  Easier to distribute processing of collections over multiple threads  More succinct and clear than anonymous inner classes Is Lambda Expression a syntactic-sugar for Anonymous Inner Class?

HOW LAMBDA EXPRESSIONS WORK? The lambda expression is represented by a new method, and is invoked at run-time using invokedynamic & LambdaMetafactory JAVA 8 FEATURES JVM generation JVM translation Lambda Expression is not a syntactic-sugar for Anonymous Inner Class

STREAM API Java 7 Lambda Expressions Default Methods Stream API New Date/Time APINashorn Java 8 Others JAVA 8 FEATURES

DEFINITION OF STREAM JAVA 8 FEATURES Streams are a FP design pattern for processing sequences of elements sequentially or in parallel

STREAM IN JAVA 8 - EXAMPLE Given a list of photos, I want to find 5 photo names that follow top 3 photos whose average rating is higher than 6, sorted by rating and the total amount of ratings given JAVA 8 FEATURES


STREAM STYLE JAVA 8 FEATURES Coding in Stream API-way  Internally iterates through the elements  Manipulate the collection data easier and faster  Focus on "what" to do instead of "how" to do it  The ability to use multiple processor cores for collection processing

STREAM OPERATIONS JAVA 8 FEATURES Intermediate operations - Lazy processing - Stateless: filter, map, flatMap, peek - Stateful: distinct, sorted, skip - Short-circuiting : limit Terminal operations - Eager processing - forEach, reduce, collect, max, count - Short-circuiting: anyMatch, allMatch, noneMatch, findFirst, findAny - Escape-hatch: iterator, spliterator

DEFAULT METHODS Java 7 Lambda Expressions Default Methods Stream API New Date/Time APINashorn Java 8 Others JAVA 8 FEATURES

How to add forEach(Consumer) method into List interface? persons.forEach(person ->; DEFAULT METHODS JAVA 8 FEATURES Default Methods allow to add default implementations to new and/or existing methods of existing interface

CLASS-EXTENDED IN JAVA 8 JAVA 8 FEATURES Multiple Inheritances  behaviors only, no state ‘Diamond Problem’  Solving manually

CLASS-EXTENDED IN OTHER LANGUAGES Scala Traits (or Ruby Mix-ins) JAVA 8 FEATURES C# Extension Methods

NEW DATE & TIME API Java 7 Lambda Expressions Default Methods Stream API New Date/Time APINashorn Java 8 Others JAVA 8 FEATURES

DATE AND TIME API  Immutable-value classes  Domain-driven design  Separation of chronologies JAVA 8 FEATURES Problems of current Date Time API  Date, Calendar and SimpleDateFormatter are not thread-safe  Poor API design: years start at 1900, months start at 0  No Non-timezone dates/times, durations, periods and intervals New Date and Time API Great but not a Java Standard API Joda-Time

NEW DATE AND TIME API EXAMPLE JAVA 8 FEATURES  LocalDate, LocalTime, LocalDateTime, ZonedDateTime  Clock, Duration, Period, ZoneId, ZoneOffset Domain-driven Date and Time Date and Time API classes

NEW JAVASCRIPT ENGINE (NASHORN) Java 7 Lambda Expressions Default Methods Stream API New Date/Time APINashorn Java 8 Others JAVA 8 FEATURES

NEW JAVASCRIPT ENGINE (NASHORN) JAVA 8 FEATURES Why Nashorn Engine?  Full 100% ECMA262-compliant (edition 5.1)  Compiles JS to Java byte-code based on invokedynamic  Not match V8 performance, but 2-10x faster than Rhino  jjs command line tool Applying Nashorn: Avartar.js and Project Avatar

OTHER FEATURES Java 7 Lambda Expressions Default Methods Stream API New Date/Time APINashorn Java 8 Others JAVA 8 FEATURES

OTHER FEATURES JAVA 8 FEATURES Static Methods on Interfaces At beginning, Java allows static fields and static inner types in interface, why not static methods? Yes, it is in Java 8 Optional Class Type Annotations 3rd-parties like Checker Framework use Java Compiler Plug-in and Pluggable Annotations Processing APIs to develop their own analyses

OTHER FEATURES (CON’T) JAVA 8 FEATURES Repeating Annotations Method Parameter Reflection  How to get name of method parameters?  java.lang.reflect.Executable.getParameters  Compile the source file with the -parameters

CONCLUSIONS New Features in Java 8 Lambda Expressions Default Methods Stream API New Date/Time APINashorn Others JAVA 8 FEATURES Change the way we write applications

RESOURCES • whats-new-2157071.html • hing-about-java-8/ • java-8-that-will-change-how-you-code/ • • • Duke 8 image [] • Stream image []


THANK YOU © 2013 KMS Technology

Add a comment

Related presentations

Speaker: Matt Stine Developing for the Cloud Track Marc Andressen has famou...

This presentation explains how to develop a Web API in Java using (JAX-RS or Restl...

1 App,

1 App,

November 10, 2014

How to bring innovation to your organization by streamlining the deployment proces...

Cisco Call-control solutions can handle voice, video and data

Nathan Sharp of Siemens Energy recently spoke at the SAP Project Management in Atl...

Related pages

What's New in JDK 8 - Oracle | Integrated Cloud ...

This document summarizes features and enhancements in Java SE 8 and in JDK 8, Oracle's implementation of Java SE 8.
Read more

JDK 8 Features - OpenJDK

Add lambda expressions (closures) and supporting features, including method references, enhanced type inference, and virtual extension methods, to the Java ...
Read more

Informationen zu Java 8

Informationen zu Java 8 Java 8 ist das neueste Release von Java und enthält neue Funktionen, Verbesserungen und Bugkorrekturen zur Verbesserung der ...
Read more

8 Great Java 8 Features No One's Talking about - InfoQ

In this article Tal Weiss focuses on some lesser known API's in the new Java 8.
Read more

Java 8 Information

Java 8 Information Java 8 is the latest release for Java that contains new features, enhancements and bug fixes to improve efficiency to develop and run ...
Read more

Java 8 Language Features | Android Developers

Android N introduces support for Java 8 language features that you can use when developing apps that target Android N. This page describes the new language ...
Read more

Java 1.8 (JDK8): What's new? Code examples and performance ...

In a previous post, I talked about new features and performance of java 1.7. Java 7 has now been released a while ago and Java 8 is coming. Java 1.8 is ...
Read more

10 versteckte Java-8-Features, die Sie kennen sollten ...

Java 8 kann mehr als Lambda-Ausdrücke. Es gibt einige versteckte Features, die den Alltag des Entwicklers erleichtern. Kennen Sie diese Features?
Read more

Java 8: Features und Änderungen im neuen Java - Karl Lorey

Java 8, das im September 2013 erscheinen soll, bietet zahlreiche neue Features, diverse Änderungen und kleinere Neuerungen im Detail. Dieser Artikel soll ...
Read more

Java 8 Tutorial - Benjamin Winterberg

Learn Java SE 8 by example: Lambda Expressions, Default Interface Methods, Method References, Streams, Date API, Annotations and more
Read more