Table of Contents

Title Page

About The Author

Code Examples – Read Me

Errata

Chapter 1 – Java 8 and Interface Enhancements

Introduction to Java 8

Default Methods and Functional Interfaces

Creating Default Methods

Understanding the Importance of Default Methods

Defining a Default Method

Overriding Default Methods

Using Inheritance with Default Methods

Working with Single Inheritance

Working with Multiple Inheritance

Understanding how Diamond Inheritance Works

Resolving Overridden Default Methods

Using Default Methods

Extending Existing Interfaces

Using Default Methods to Supplement Adapter Classes

Using Default Methods in Core Java Classes

Using a Class to Support Default Methods

Understanding the Difference between an Abstract Class and Interfaces

Using Static Interface Methods

Functional Interfaces

Creating a Functional Interface

Using  the @FunctionalInterface Annotation

Overriding Object Class Methods in a Functional Interface

Using Functional Interfaces in the Core Libraries

Conclusion

Chapter 2 – Lambda Expressions

Understanding Lambda Expressions

Inferring the Type of the Target

Creating Lambda Expressions

Lambda Expression Syntax Rules

Declaring Parameter Types

Mixing Parameter Declarations

Omitting Parentheses

Eliminating the Block Statement

Using Multiple Statements in a Lambda Expression Body

Using a Return Value

Writing Succinct Lambda Expressions

Capturing Variables in a Lambda Expression

Differentiating between a Lambda Expression and a Closure

Method and Constructor References

Using Static Method References

Using Instance Method References

Using Constructor References

Working with Lambda Expressions

Using Lambda Expressions with Variable Declarations

Using Lambda Expressions as a Return Value

Using Exceptions with a Lambda Expression

Using Lambda Expressions with the Tertiary Operator

Casting Lambda Expressions

Using Lambda Expressions to Initialize an Array

Writing Recursive Lambda Expressions

Using the java.util.function Functional Interfaces

Using the Predicate Interface

Using the Function Interface

Using the BiFunction Interface

Using the Consumer Interface

Using the Supplier Interface

Using Operator Type Interfaces

Using the UnaryOperator Interface

Using the BinaryOperator Interface

Conclusion

Chapter 3 – Streams

Streams

Stream Characteristics

Streams Do Not Store Elements

Streams Can Be Unbounded

Streams Do Not Modify the Original Source

A Stream May Be Ordered

Automatic Parallelization

An Overview of Stream Methods

Creating a Stream

Using the Stream Interface’s of Method

Using the Collection Class’ stream Method

Using a Stream.Builder Interface

Using the builder method

Generating Infinite Streams

Using the iterate Method

Concatenating Streams

Generating an Empty Stream

Using Stream Methods

The Part Example Class

Using the forEach Method

Using the forEachOrdered Method

Using the map Method

Using Other Map Methods

Using the flatmap Method

Using the filter Method

Using the Match Type Methods

Using the findFirst Method

Using the findAny Method

Using the Optional Class

Using the reduce Method

Using the Collector Interface and the collect Method

Using the Collects Class

Using the iterator Method

Using the sorted Method

Using the distinct Method

Using the limit Method

Using the skip Method

Using the max, min, and count Methods

Streams for Primitive Types

Using the IntStream Interface

Understanding Lazy and Eager Evaluation

Using Short-Circuit Methods

Using Parallel Stream Operations

Conclusion

Chapter 4 – Date and Time

Introduction

Why a New API?

A Simple Example

The ISO-8601 String Format

Design Considerations

Understanding the Standard Method Names

Understanding the of Type Methods

Understanding the from Method

Understanding the parse Method

Understanding the format Method

Understanding the get Type Method

Understanding the is Type Methods

Understanding the with Type Methods

Understanding the plus Type Methods

Understanding minus Type Methods

Understanding the to Type Methods

Understanding the at Type Methods

Overview of the Date and Time Packages

Getting the Current Time

Working with the Instant Class

Creating an Instant

Creating an Instant Based on the Epoch

Creating an Instant Based on Parsing a UTC String

Creating an Instant by Adding or Subtracting a Time from an Instant

Using the Instant Class’ get Type Methods

Working with Time Intervals

Creating Offsets Using the of Type Methods

Creating Offsets Using the with Type Methods

Creating a Duration Using the parse Method

Creating a Duration by Adding or Subtracting a Unit

Using the Duration Class

Using the Period Class

Using Date and Time Classes

Creating Date and Time Classes

Date and Time get Type Methods

Adjusting a Date or Time

Using the YearMonth, MonthDay, and Year Classes

Comparing MonthDay Instances

Using the Enumerations DayOfWeek and Month

Using the DayOfWeek Enumeration

Using the Month Enumeration

Working with the Time Zone and Offset Classes

Obtaining Available Zone IDs

Working with ZoneOffsets

Working with Zone Rules

Formatting, Queries, and Value-Based Classes

Formatting Dates and Times

Using Temporal Queries

Understanding Value-Based Classes

Conclusion

Chapter 5 – Odds and Ends

Introduction

Using the Nashorn JavaScript Engine

Accessing the Nashorn Engine

Executing JavaScript Code

Executing Java Code from JavaScript

Implementing a Java Interface

File IO Enhancements

Using the FileFilter Interface

Using the PathMatcher Interface

Using the Files Class’ list Method

Using the Files Class’ walk Method

Using the Path Class’ lines Method

Concurrency Enhancements

Using the Arrays Class’ parallelSort Method

Using the Arrays Class’ parallelSetAll Method

Using the Arrays Class’ parallelPrefix Method

Collections Enhancements

Using the forEachRemaining Method

Using the replace Type Methods

Using the compute Type Methods

Project Jigsaw and Compact Profiles

The Compact Profiles

Using Compact Profiles

Other Enhancements

Javadoc Enhancements

Security Enhancements

VM Related Enhancements

Core Java Enhancements

Conclusion

Appendix - Date and Time Classes

Of Type Methods

The from Method

The parse Method

Get Type Methods

Is Type Methods

With Type Methods

Plus Type Methods

Minus Type Methods

To Type Methods

At Type Methods

Other Books from P8tech