Whats New in Java 8

58 %
42 %
Information about Whats New in Java 8
Software

Published on May 8, 2014

Author: buzdin

Source: slideshare.net

What’s new in Java 8 Maxim Zakharenkov 3 April, 2014

Existing presentations • Новое в JDK 8. Александр Ильин, Oracle https://www.youtube.com/watch?v=lSnNWRABA1s • JDK8: Stream style, Sergey Kuksenko, Oracle http://www.slideshare.net/SergeyKuksenko/jdk8-stream-style • More on slideshare

What this talk is about • Streams • Stream notes • Some other new features in Java 8 – Optional<?> – Annotations – parallelSort – Concurrency – Some other stuff

Streams Other presentation slides here

filter()

filter() map()

filter() map() map()

filter() map() map() distinct()

filter() map() map() distinct()collect()

Stream notes: Short circuiting Random random = new Random(); int[] result = IntStream .generate(() ->random.nextInt()) .sorted() .toArray();

Stream notes: parallel forEach DEMO

Stream notes: parallel forEach • forEach does not preserve order! • Use forEachOrdered if order matters

Stream notes: not reusable IntStream stream = Arrays.stream(new int[]{1, 2, 3, 4}); List<Object> list = stream.boxed().collect(Collectors.toList()); // this throws java.lang.IllegalStateException double average = stream.average().getAsDouble();

Optional results 1 public String findById(int id) { // ... return …; }

Optional results 2 public String findById(int id) { // ... return …; } String result = findById(10);

Optional results 3 public String findById(int id) { // ... return …; } String result = findById(10); prefix = result.substring(0, 3);

Optional results 4 public String findById(int id) { // ... return …; } String result = findById(10); if(result != null) { prefix = result.substring(0, 3); }

Optional results 5 public String ? findById(int id) { // ... return …; } String result = findById(10); prefix = result.substring(0, 3);

Optional results 6 public Optional<String> findById(int id) { // ... return …; } if(result.isPresent()) { }

Annotations public @NonNull String findById(int id) { // ... return …; }

Checker framework http://types.cs.washington.edu/checker- framework/current/checkers-manual.html

Checker framework • @Interned String intern() { ... } // return value • int compareTo(@NonNull String other) { ... } // parameter • String toString(@ReadOnly MyClass this) { ... } // receiver • @NonNull List<@Interned String> messages; // generics: non- null list of interned Strings • @Interned String @NonNull [] messages; // arrays: non-null array of interned Strings • myDate = (@ReadOnly Date) readonlyObject; // cast

Arrays.parallelSort • Works faster • Everyting has own cost – DualPivotQuickSort - sequental – MergeSort - parallel

Parallel sort of 50M elements (on my 4 core laptop) • Single threaded DualPivotQuickSort: 47sec • Parallel merge sort: 21sec • Sequential stream: 95sec • Parallel stream: 104sec

Parallelism, is it good or bad? (example) • 2 CPU • Concurrent clients - 1000 queries per second • Single sequential sort - 2ms • Single parallel sort - 1ms + sync overhead ~1.2ms • Less transactions per second with parallel sort • Parallel algorithms do not always fit well

HashMap 0 key1 1 2 3 4 5 6 key2 key3

HashMap before Java 8 0 key1 1 2 3 4 5 6 key2 key3 key4 key4

HashMap in Java 8 0 key1 1 2 3 4 5 6 key2 key3 key4 key4

MissionControl • Cool tool for JVM diagnostics • Comes with JDK installation (jmc executable • Now we have 3 similar tools in JDK – jconsole – jvisualvm – jms

Future of frameworks • Type-safe property references in Hibernate- like query languages • JUnit, Mockito-like frameworks with method references • Event handlers • Better XML and JSON serializers • - ….

QA

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 ...

What's New in JDK 8. Java Platform, Standard Edition 8 is a major feature release. This document summarizes features and enhancements in Java SE 8 and in ...
Read more

Read What's New in Java 8 | Leanpub

This code is perfectly valid Java 8. The first line defines a function that prepends “@” to a String. The last two lines define functions that do the ...
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

What's New in Java 8 | Pluralsight

A quick overview of most of the new features of Java 8. The course covers lambda expressions and the Stream API but also many new additions scattered all ...
Read more

What’s new in Java 8: Lambdas - O'Reilly Media

Greek lowercase letter Lambda (source: Wikimedia Commons). Java 8 is here, and, with it, come lambdas. Although long overdue ...
Read more

Java 8: What’s New In It ? | InApp

Oracle launched a new version of java Jdk1.8 with a lot of features. Some of the important features are provided below. 1) Lambda. JDK 1.8 allows you to ...
Read more

What's New in Java 8: Lambdas | Udemy

Please confirm that you want to add What's New in Java 8: Lambdas to your Wishlist. Add to Wishlist ...
Read more

Information about Java 8

Java 8 Information Java 8 is the latest release for Java that contains new features, ...
Read more

Java Programming Language Enhancements - Oracle

Java Programming Language ... and Streams in Java SE 8 describe new and enhanced classes ... the new java.lang.AutoCloseable ...
Read more

What's new for Java 7 - Eclipse

What's new for Java 7. Java 7 comes with a set of small enhancements to the Java language (aka Project Coin), a new byte code to dynamically invoke methods ...
Read more