Java Reference
In-Depth Information
tures (the ability to include default and static methods) and discussed the concept of
functional interfaces.
This chapter presents many examples of functional programming, often showing sim-
pler ways to implement tasks that you programmed in earlier chapters (Fig. 17.1)
Pre-Java-SE-8 topics
Corresponding Java SE 8 discussions and examples
Chapter 7, Arrays and ArrayLists
Sections 17.3-17.4 introduce basic lambda and streams capabili-
ties that process one-dimensional arrays.
Chapter 10, Object-Oriented
Programming: Polymorphism
and Interfaces
Section 10.10 introduced the new Java SE 8 interface features
( default methods, static methods and the concept of func-
tional interfaces) that support functional programming.
Chapter 12, GUI Components:
Part 1
Section 17.9 shows how to use a lambda to implement a Swing
event-listener functional interface.
Chapter 14, Strings, Characters
and Regular Expressions
Section 17.5 shows how to use lambdas and streams to process
collections of String objects.
Chapter 15, Files, Streams and
Object Serialization
Section 17.7 shows how to use lambdas and streams to process
lines of text from a file.
Chapter 22, GUI Components:
Part 2
Discusses using lambdas to implement Swing event-listener
functional interfaces.
Chapter 23, Concurrency
Shows that functional programs are easier to parallelize so that they
can take advantage of multi-core architectures to enhance perfor-
mance. Demonstrates parallel stream processing. Shows that
Arrays method parallelSort improves performance on multi-
core architectures when sorting large arrays.
Chapter 25, JavaFX GUI: Part 1
Discusses using lambdas to implement JavaFX event-listener
functional interfaces.
Fig. 17.1 | Java SE 8 lambdas and streams discussions and examples.
17.2 Functional Programming Technologies Overview
In the preceding chapters, you learned various procedural, object-oriented and generic
programming techniques. Though you often used Java library classes and interfaces to per-
form various tasks, you typically determine what you want to accomplish in a task then
specify precisely how to accomplish it. For example, let's assume that what you'd like to
accomplish is to sum the elements of an array named values (the data source ). You might
use the following code:
int sum = 0 ;
for ( int counter = 0 ; counter < values.length; counter++)
sum += values[counter];
This loop specifies how we'd like to add each array element's value to the sum —with a for
repetition statement that processes each element one at a time, adding each element's value
to the sum . This iteration technique is known as external iteration (because you specify
how to iterate, not the library) and requires you to access the elements sequentially from
 
 
Search WWH ::




Custom Search