Java 8 & 9 in Action, Second Edition
Lambda, streams, functional and reactive programming
Raoul-Gabriel Urma, Mario Fusco, Alan Mycroft
  • MEAP began March 2017
  • Publication in Early 2018 (estimated)
  • ISBN 9781617293566
  • 550 pages (estimated)
  • printed in black & white


An eBook copy of the previous edition, Java 8 in Action (First Edition), is included at no additional cost. It will be automatically added to your Manning Bookshelf within 24 hours of purchase.

Manning's bestselling Java 8 book has been revised for Java 9! In Java 8 and 9 in Action, you'll build on your existing Java language skills with the newest features and techniques. After a practical introduction to lambdas using real-world Java code, you'll dive into the Streams API. Next, you'll discover event-driven reactive programming and see how the Java Module System (aka Jigsaw) will help change how you structure your code. This book also explains functional programming in Java, working with collections, and more.

"This is an excellent introduction to the newest features in Java 8 and 9. It provides clear and concise examples to help clarify how to use Java's newest features such as streams, lambda functions, and reactive streams."

~ Meredith Godar

"Hands on Java 8 and 9, simple and elegantly explained."

~ Deepak Bhaskaran

Table of Contents detailed table of contents

Part 1: Fundamentals

1. Java 8 & 9: why you should care?

2. Passing code with behavior parameterization

2.1. Coping with changing requirements

2.1.1. First attempt: filtering green apples

2.1.2. Second attempt: parameterizing the color

2.1.3. Third attempt: filtering with every attribute you can think of

2.2. Behavior parameterization

2.2.1. Fourth attempt: filtering by abstract criteria

2.3. Tackling verbosity

2.3.1. Anonymous classes

2.3.2. Fifth attempt: using an anonymous class

2.3.3. Sixth attempt: using a lambda expression

2.3.4. Seventh attempt: abstracting over List type

2.4. Real-world examples

2.4.1. Sorting with a Comparator

2.4.2. Executing a block of code with Runnable

2.4.3. Returning a result using Callable

2.4.4. GUI event handling

2.5. Summary

3. Lambda expressions

3.1. Lambdas in a nutshell

3.2. Where and how to use lambdas

3.2.1. Functional interface

3.2.2. Function descriptor

3.3. Putting lambdas into practice: the execute around pattern

3.3.1. Step 1: Remember behavior parameterization

3.3.2. Step 2: Use a functional interface to pass behaviors

3.3.3. Step 3: Execute a behavior!

3.3.4. Step 4: Pass lambdas

3.4. Using functional interfaces

3.4.1. Predicate

3.4.2. Consumer

3.4.3. Function

3.5. Type checking, type inference, and restrictions

3.5.1. Type checking

3.5.2. Same lambda, different functional interfaces

3.5.3. Type inference

3.5.4. Using local variables

3.6. Method references

3.6.1. In a nutshell

3.6.2. Constructor references

3.7. Putting lambdas and method references into practice!

3.7.1. Step 1: Pass code

3.7.2. Step 2: Use an anonymous class

3.7.3. Step 3: Use lambda expressions

3.7.4. Step 4: Use method references

3.8. Useful methods to compose lambda expressions

3.8.1. Composing Comparators

3.8.2. Composing Predicates

3.8.3. Composing Functions

3.9. Similar ideas from mathematics

3.9.1. Integration

3.9.2. Connecting to Java 8 lambdas

3.10. Summary

Part 2: Functional-style data processing with streams

4. Introducing streams

4.1. What are streams?

4.2. Getting started with streams

4.3. Streams vs. collections

4.3.1. Traversable only once

4.3.2. External vs. internal iteration

4.4. Stream operations

4.4.1. Intermediate operations

4.4.2. Terminal operations

4.4.3. Working with streams

4.5. Summary

5. Working with streams

5.1. Filtering

5.1.1. Filtering with a predicate

5.1.2. Filtering unique elements

5.2. Slicing a stream

5.2.1. Slicing using a predicate

5.2.2. Truncating a stream

5.2.3. Skipping elements

5.3. Mapping

5.3.1. Applying a function to each element of a stream

5.3.2. Flattening streams

5.4. Finding and matching

5.4.1. Checking to see if a predicate matches at least one element

5.4.2. Checking to see if a predicate matches all elements

5.4.3. Finding an element

5.4.4. Finding the first element

5.5. Reducing

5.5.1. Summing the elements

5.5.2. Maximum and minimum

5.6. Putting it all into practice

5.6.1. The domain: Traders and Transactions

5.6.2. Solutions

5.7. Numeric streams

5.7.1. Primitive stream specializations

5.7.2. Numeric ranges

5.7.3. Putting numerical streams into practice: Pythagorean triples

5.8. Building streams

5.8.1. Streams from values

5.8.2. Stream from nullable

5.8.3. Streams from arrays

5.8.4. Streams from files

5.8.5. Streams from functions: creating infinite streams!

5.9. Summary

6. Collecting data with streams

6.1. Collectors in a nutshell

6.1.1. Collectors as advanced reductions

6.1.2. Predefined collectors

6.2. Reducing and summarizing

6.2.1. Finding maximum and minimum in a stream of values

6.2.2. Summarization

6.2.3. Joining Strings

6.2.4. Generalized summarization with reduction

6.3. Grouping

6.3.1. Manipulating grouped elements

6.3.2. Multilevel grouping

6.3.3. Collecting data in subgroups

6.4. Partitioning

6.4.1. Advantages of partitioning

6.4.2. Partitioning numbers into prime and nonprime

6.5. The Collector interface

6.5.1. Making sense of the methods declared by Collector interface

6.5.2. Putting them all together

6.6. Developing your own collector for better performance

6.6.1. Divide only by prime numbers

6.6.2. Comparing collectors' performances

6.7. Summary

7. Parallel data processing and performance

7.1. Parallel streams

7.1.1. Turning a sequential stream into a parallel one

7.1.2. Measuring stream performance

7.1.3. Using parallel streams correctly

7.1.4. Using parallel streams effectively

7.2. The fork/join framework

7.2.1. Working with RecursiveTask

7.2.2. Best practices for using the fork/join framework

7.2.3. Work stealing

7.3. Spliterator

7.3.1. The splitting process

7.3.2. Implementing your own Spliterator

7.4. Summary

Part 3: Effective programming with lambdas

8. Collection API Enhancements

8.1. Collection factories

8.1.1. Creating collections

8.2. Working with List and Set

8.3. Working with Map

8.4. Improved ConcurrentMap

8.5. Summary

9. Testing and debugging with lambdas

10. Default methods

11. Designing a DSL with lambdas

Part 4: Everyday Java

12. Working with collections in Java 8 and 9

13. Using Optional as a better alternative to null

14. New Date and Time API

15. Java Module System

Part 5: Reactive programming

16. CompletableFuture: composable asynchronous programming

16.1. Futures

16.1.1. Futures limitations

16.1.2. Using CompletableFutures to build an asynchronous application

16.2. Implementing an asynchronous API

16.2.1. Converting a synchronous method into an asynchronous one

16.2.2. Dealing with errors

16.3. Make your code non-blocking

16.3.1. Parallelizing requests using a parallel Stream

16.3.2. Making asynchronous requests with CompletableFutures

16.3.3. Looking for the solution that scales better

16.3.4. Using a custom Executor

16.4. Pipelining asynchronous tasks

16.4.1. Implementing a discount service

16.4.2. Using the Discount service

16.4.3. Composing synchronous and asynchronous operations

16.4.4. Combining two CompletableFutures-dependent and independent

16.4.5. Reflecting on Future vs. CompletableFuture

16.4.6. Effectively using timeouts

16.5. Reacting to a CompletableFuture completion

16.5.1. Refactoring the best-price-finder application

16.5.2. Putting it to work

16.6. Summary

17. CompletableFuture API

18. Flow API

Part 6: Functional programming

19. Thinking functionally

20. Functional programming techniques

21. Practical Design with functional programming

22. Conclusions and where next for Java

About the Technology

The release of Java 9 builds on what made Java 8 so exciting. In addition to Java 8's lambdas and streams, Java 9 adds a host of new features of its own. It includes new library features to support reactive programming, which give you new ways of thinking about programming and writing code that is easier to read and maintain. Java 9 also introduces the long-awaited Java Module System. Modules encourage you to write your code in smaller units that are easier to test, manage and release. Java 9 also helps programmers by enriching the functional-programming and streams features of Java 8.

What's inside

  • All of Java 9's new changes and features
  • Lambda expressions
  • Data processing with streams
  • Testing and debugging with lambdas
  • Reactive programming in Java
  • The Java Module System
  • Practical design with functional programming

About the reader

This book is written for programmers familiar with Java and basic OO programming.

About the authors

Raoul-Gabriel Urma is CEO and a co-founder of Cambridge Spark, a leading learning community for data scientists and developers in UK. Mario Fusco is a senior software engineer at Red Hat working at the development of the core of Drools, the JBoss rule engine. Alan Mycroft is a Professor of Computing at Cambridge and cofounder of the Raspberry Pi Foundation.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
MEAP combo $54.99 pBook + eBook + liveBook
MEAP eBook $43.99 pdf + ePub + kindle + liveBook

FREE domestic shipping on three or more pBooks