java8
TRANSCRIPT
© by mimacom ag 05/05/2014
© mimacom ag
Summary
2
• New features and concepts
• New and extended APIs
• Performance improvements
• Conclusion
• Q & A
© mimacom ag
New features and concepts
3
• Interface changes
• Lambda expressions
• Streams
• Nashorn
• Java FX improvements
© mimacom ag
Interface changes
4
• Interfaces can now define static methods:
• Interfaces can now define default methods:
© mimacom ag
Interface changes
5
• Functional interfaces:• An interface is functional if it defines exactly one abstract
method.
• Default and static methods are not abstract, so they can be
defined without compile errors.
• This annotation has been introduced to declare interfaces as
functional: @FunctionalInterface
• Runnable, Comparator or Cloneable are some examples of
functional interfaces.
© mimacom ag
Lambda expressions
6
• Functional Interfaces + Lambda Probably the biggest feature
since generics.
• They are basically used to instantiate functional interfaces, for
instance:
© mimacom ag
Lambda expressions
7
• Concrete examples:
© mimacom ag
Lambda expressions
8
• A lambda is compatible with a functional interface when their
inputs, output and checked exceptions match.
• Lambdas can capture variables outside the lambda body if the
variables are effectively final.
• Lambdas can’t be used to control the flow of the application:
© mimacom ag
Lambda expressions
9
• Advantadges:
• Less code to write.
• Flexibility to instantiate interfaces.
• Alternative to anonymous inner classes.
• Disadvantages:
• More difficult to debug.
© mimacom ag
Streams
10
• A sequence of elements supporting sequential and parallel
aggregate operations.
• A stream can be used just once.
• The most common way to obtain a stream is from collections:
© mimacom ag
Streams
11
• Two kind of operations:
• Intermadiate: Keep the stream open and allow to concatenate
operations with the same stream.
• Some of them: Filter, map, flatMap, peek, distinct, sorted,
etc.
• Terminal: It must be the final operation, once this one is
executed, the stream is consumed and is no longer available.
• Some of them: forEach, toArray, reduce, collect, sum, min,
max, etc.
© mimacom ag
Streams
12
• A couple of examples:
© mimacom ag
Nashorn
13
• New JS engine, Rhino’s successor.
• Ability to access Java classes from JS… and
viceversa.
• Nashorn + Avatar.js Node.js functionality
© mimacom ag
Nashorn
14
• Why use Nashorn (extracted from Oracle):• Can reuse existing Java libraries and middleware
• Can take advantage of multiple cores
• Can be secured using the Java security model
• Can be managed using existing Java tools
• VisualVM, MBeans, Flight Recorder, Mission Control
• Can access Java Platform APIs to complement node APIs
• BigInteger, Date, Calendar, XML, SQL, Multicast, etc
• Small enough for embedded usage (less than 2Mb)
© mimacom ag
JavaFX improvements
15
• It is the sustitute of Swing and it has been
improved in java 8.
• New look with Modena theme.
© mimacom ag
JavaFX improvements
16
• True 3D support.
• Video & audio recording.
• Printing support
• Added new controls
• Fully open source.
© mimacom ag
New and extended APIs
17
• New java.time API
• java.util.function
• Collection API additions
• Other additions
© mimacom ag
New java.time API
18
• Similar to JodaTime library.
• Instead of include JodaTime in the JDK, it was
redesigned from scratch.
• Useful value types:• LocalDateTime, LocalDate, LocalTime.
• Year, Month, YearMonth. MonthDay, DayOfWeek.
• Instant, Period, ZonedDateTime.
© mimacom ag
Java.util.function
19
• Set of functional interfaces widely used in the new APIs of Java 8.
• Here are a few:
• Function<T, R> - take a T as input, return an R as ouput.
• Predicate<T> - take a T as input, return a boolean as output.
• Consumer<T> - take a T as input, perform some action and
don't return anything.
• Supplier<T> - with nothing as input, return a T.
• BinaryOperator<T> - take two T's as input, return one T as
output, useful for "reduce" operations.
© mimacom ag
Colletion API additions
20
• The ability that interfaces can define default methods have
introduced a lot of additionson the colletion interfaces. Some of
them:
• Iterable.forEach(Consumer)
• Iterator.forEachRemaining(Consumer)
• Collection.removeIf(Predicate)
• Collection.spliterator()
• List.sort(Comparator)
• List.replaceAll(UnaryOperator)
• Map.forEach(BiConsumer)
• …
© mimacom ag
Other additions
21
• There are several additions with a lot of new classes and new
methods:
• Concurrency API additions.
• IO/NIO API additions.
• New methods and classes in java.lang, java.util and in several places more.
© mimacom ag
Performance improvements
22
© mimacom ag
Conclusion
23
• A lot of additions in this release.
• Lambdas and functional interfaces will change a little bit the way
people is developing.
• But several of them were already in antoher languages, so Oracle
has not invented nothing new.
• It seems that they have worked really hard to improve
performance, let’s see if it is true!!!
© mimacom ag
24
References
• http://docs.oracle.com/javase/8/docs/api/overview-summary.html
• http://www.techempower.com/blog/2013/03/26/everything-about-
java-8/
• http://www.infoq.com/articles/nashorn
• https://avatar.java.net/
• http://java.dzone.com/articles/whats-new-java-8-part-i-javafx
• https://blogs.oracle.com/thejavatutorials/entry/
learn_more_about_performance_and
© mimacom ag
25
© mimacom ag
customer orientedUser friendlyCompetentlyQualitatively
Efficient
26
…the open source integrator