Lambdas and Streams in Java 8

By Klaus Kreft & Angelika Langer

Java 8 comes with several new language features. First, there is support for expressing anonymous functions: Java 8 has lambda expressions and method/constructor references for this purpose. Second, interface methods can have an implementation in Java 8: there are default methods and static methods in interfaces in addition to the well-known abstract interface methods.

Lambda expressions are essential in conjunction with new JDK abstractions such as Stream, ComputableFuture and the like. These new JDK APIs are clumsy to use without lambdas and method references. The non- abstract interface methods were used for the design and implementation of the new JDK APIs.

The JDK's collection framework is radically overhauled in Java 8: it has bulk operations that take functions and apply them to all elements in a collection. The session provides an overview of the new operations and some insight into their inner workings. The centerpiece of the new API is the interface java.util.stream.Stream. We will explore what streams are, how they differ from collections, how their operations are executed (in parallel or sequentially), why some operations are intermediate and others terminal, why most operations are stateless, and what fluent programming is.

Audience: Java developers with an interest in Java 8.

Level: intermediate

Prerequisite: basic knowledge of Java