0% found this document useful (0 votes)
15 views

1.3.1 Java Streams Overview

Uploaded by

deadmanalive611
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

1.3.1 Java Streams Overview

Uploaded by

deadmanalive611
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Overview of Java Streams

Douglas C. Schmidt
[email protected]
www.dre.vanderbilt.edu/~schmidt
Professor of Computer Science
Institute for Software
Integrated Systems
Vanderbilt University
Nashville, Tennessee, USA
Learning Objectives in this Part of the Lesson
• Understand Java streams structure &
Stream source
functionality
Input x

Aggregate operation (behavior f)

Output f(x)

Aggregate operation (behavior g)

Output g(f(x))

Aggregate operation (behavior h)

2
Learning Objectives in this Part of the Lesson
• Understand Java streams structure &
Stream source
functionality, e.g.
Input x
• Fundamentals of streams
Aggregate operation (behavior f)

Output f(x)

Aggregate operation (behavior g)

Output g(f(x))

Aggregate operation (behavior h)

3
Learning Objectives in this Part of the Lesson
• Understand Java streams structure &
Stream source
functionality, e.g.
Input x
• Fundamentals of streams
• & the evolution of streams Aggregate operation (behavior f)

Output f(x)

Aggregate operation (behavior g)

Output g(f(x))

Aggregate operation (behavior h)

4
Overview of
Java Streams

5
Overview of Java Streams
• Java streams are a framework first
introduced into the Java class library
in Java 8

See docs.oracle.com/javase/tutorial/collections/streams
6
Overview of Java Streams
• A stream is a pipeline of aggregate operations that process a sequence of
elements (aka, “values” or “data”) Input x

Aggregate operation (behavior f)

Output f(x)

Aggregate operation (behavior g)

Output g(f(x))

Aggregate operation (behavior h)

See docs.oracle.com/javase/tutorial/collections/streams
7
Overview of Java Streams
• A stream is a pipeline of aggregate operations that process a sequence of
elements (aka, “values” or “data”) Input x

Aggregate operation (behavior f)

Output f(x)

Aggregate operation (behavior g)

Output g(f(x))

An aggregate operation is a higher- Aggregate operation (behavior h)


order function that applies a “behavior”
param to every element in a stream.

See en.wikipedia.org/wiki/Higher-order_function
8
Overview of Java Streams
• A stream is a pipeline of aggregate operations that process a sequence of
elements (aka, “values” or “data”) Input x

Aggregate operation (behavior f)

Output f(x)

Aggregate operation (behavior g)

Output g(f(x))

Aggregate operation (behavior h)


Behavior parameterization simplifies
coping with changing requirements.

See blog.indrek.io/articles/java-8-behavior-parameterization
9
Overview of Java Streams
• A stream is a pipeline of aggregate operations that process a sequence of
elements (aka, “values” or “data”) Input x

Aggregate operation (behavior f)

Output f(x)

Aggregate operation (behavior g)

Output g(f(x))

Aggregate operation (behavior h)

A stream is conceptually unbounded, though it’s often bounded by practical constraints.

10
Overview of Java Streams
• A Java stream is an implementation of the POSA1 Pipes & Filters pattern

Divide an app’s tasks into multiple self-contained data


processing steps & connect these steps via intermediate
data buffers to form a data processing pipeline

See hillside.net/plop/2011/papers/B-10-Hanmer.pdf
11
Overview of Java Streams
• We use this stream as a case study example throughout this introduction
Stream Input x
.of("Ophelia","horatio",
"laertes","Gertrude", Aggregate operation (behavior f)
"Hamlet","fortinbras", ...)
.filter(s -> toLowerCase Output f(x)
(s.charAt(0)) == 'h')
.map(this::capitalize) Aggregate operation (behavior g)
.sorted()
.forEach(System.out::println); Output g(f(x))

Aggregate operation (behavior h)


Print each character in Hamlet that starts with ‘H’
or ‘h’ in consistently capitalized & sorted order.

See github.com/douglascraigschmidt/LiveLessons/tree/master/Java8/ex12
12
The Evolution of
Java Streams

13
The Evolution of Java Streams
• Java streams have evolved a bit over time

14
The Evolution of Java Streams
• Java streams have evolved a bit over time, e.g.
• Later versions of Java added some
new operations

See www.baeldung.com/java-9-stream-api
15 & blog.codefx.org/java/teeing-collector
The Evolution of Java Streams
• Java streams have evolved a bit over time, e.g.
• Later versions of Java added some
new operations
• Java 9 also added a new API that
implements the reactive streams
specification

See www.reactive-streams.org
16
The Evolution of Java Streams
• Java streams have evolved a bit over time, e.g.
• Later versions of Java added some
new operations
• Java 9 also added a new API that
implements the reactive streams
specification
• Reactive streams frameworks
are covered later in this course

See upcoming lessons on17RxJava & Project Reactor


End of Overview
of Java Streams

18

You might also like