Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Stream API and Lambda Expressions in Java 8
Rating: 3.9 out of 5(241 ratings)
5,433 students

Stream API and Lambda Expressions in Java 8

Understand the why and how of Java 8 Streams and Lambda Expressions and write readable and efficient code
Created byJayesh Nachnani
Last updated 2/2021
English
English [Auto],

What you'll learn

  • Java Stream API
  • Advantages of using Java Streams
  • How and why are Streams different than collections?
  • Convert legacy code into Java 8 code using Streams.
  • Map filter reduce algorithm which is the classic use case for Java Streams.
  • Creating Streams
  • Intermediate and terminal pipeline Stream Operations.
  • Why order of calling pipeline methods matters
  • Lambda Expressions and Functional Programming in Java

Course content

2 sections36 lectures1h 18m total length
  • Note on Functional Programming and Lambda Expressions0:10
  • Why learn the Stream API?3:02

    Learn the Stream API to write declarative, efficient code that filters, maps, sorts, and collects data instead of manual loops, illustrating how streams differ from collections.

  • Why use Streams: Contrast with Collections1:58

    Explore how streams provide concise, declarative code compared to traditional collections in Java 8. Learn to compute monthly transaction statistics with minimal code using streams.

  • Why use Streams: Takeaways0:52

    Adopt declarative style programming in Java, letting you specify what to do while Java handles how to do it; streams avoid reinventing the wheel, rely on pretested, optimized code.

  • How are Streams different from Collections1:43

    Learn how streams differ from collections: collections manage storage and access, while streams process data and declaratively describe the source with filtering, transformations, and aggregations.

  • Major Differences between Streams and Collections2:57

    Contrast streams with collections by showing streams have no storage, are lightweight to create, immutable and functional, lazily evaluated, with intermediate and terminal operations, possibly unbounded, and consumable.

  • Why have a different Stream API3:54

    Explore why the stream api exists separate from collections, focusing on declarative pipelines and on-demand computation that avoid large intermediate collections using map, filter, and reduce.

  • Creating Streams from Collections2:09

    Create streams from collections by calling the stream method on a collection such as an ArrayList or HashSet, using the transaction example to show output.

  • Creating Streams from Arrays1:15

    Learn to create streams from arrays using the stream method and the stream of method, with examples from the pool and port of entry to illustrate multiple stream origins.

  • Generating Infinite Streams2:22

    Generate infinite streams in Java 8 using Stream.generate with a supplier and Stream.iterate with a seed, then apply limit to prevent memory exhaustion.

  • Creating Streams from Regular Expressions1:00

    Create streams from text using a regular expression by compiling a pattern and applying split methods, demonstrating how a hash-separated string yields a stream.

  • Stream Operations2:59

    Explore how streams form a pipeline from source to terminal operation, with intermediate operations like map and sorted that are lazy, and short-circuit operations such as limit for infinite streams.

  • Introduction to Intermediate Operations3:32

    Explore how intermediate operations filter a stream of transactions using a lambda predicate, yielding three debit transactions when a terminal operation counts the results.

  • Intermediate Operations: Filter1:55

    Explore how intermediate operations are lazy and require a terminal operation to execute. Removing the terminal step leaves nothing to run, proving streams optimize performance and memory use.

  • Intermediate Operations: Map1:51

    Explore map as a transformation in the stream api, projecting objects to only the required properties, such as extracting transaction amounts with a lambda and printing them.

  • Intermediate Operations: Chaining1:30

    Chain filter and map intermediate operations to select debit transactions, map them to amounts, and apply a terminal operation to print results.

  • Intermediate Operations: Sorting1:01

    Sort a stream by the amount field using sorted, then apply reversed to order values in descending order and display the resulting amounts.

  • Introduction to Terminal Operations1:42

    Learn terminal operations in the java 8 stream API, which produce a result or side effect, consume the stream, require a new stream for reuse, and enable short-circuiting with findFirst.

  • Terminal Operation: collect1:37

    Learn to use the terminal operation to group sums by month, switch to averaging long for averages, and use summarizing to obtain all summary statistics.

  • Terminal Operation: collect (continued)1:44

    Explore collectors in Java 8 streams to compute sums by month, averages by month, and summary statistics, while collecting items into collections and grouping by criteria.

  • Why Order Matters3:01

    Order the operations in streams to minimize computations by filtering before mapping, saving CPU cycles on large data sets, as the days-of-week example shows map-first vs filter-first.

  • Stream API Quiz
  • Congratulations and Next Steps0:43

    Conclude the course by inviting learners to explore streams and interview questions in the next lecture, share feedback via the form, and rate the course to support future content.

  • Bonus: Interview Questions0:06
  • Feedback Form0:09

Requirements

  • Basic Java programming knowledge

Description

Ever wondered why were Streams introduced in Java 8 and what are the advantages of using Java Streams? How and why are Streams different than collections? The Stream API is one of the most misunderstood features of Java 8. This course covers the Stream API in Java 8 in detail.

At the end of this quick free course you would confidently be able to answer the whys and hows of the Stream API, know the key differences between the Stream API and Java Collections and have a good understanding of intermediate and terminal pipeline Stream Operations. We will cover groupingby which is an exciting feature of Streams. We will also go through the map filter reduce algorithm which is the classic use case for Java Streams. The course also covers various ways of creating Streams and the reason why order of calling the Stream API pipeline methods matters. If you are someone who wants to learn the nuances of Java 8 Streams and explain these to those around you, then this course is for you. The course is packed with hands on coding examples, so it would enable you to follow along.

The course also covers Lambda Expressions and introduces Functional Programming in Java 8

Who this course is for:

  • Java Developers wanting to truly understand the Stream API and it's significance
  • Developers wanting to quickly get the gist of Stream API with hands on examples
  • If you are someone who wants to learn the nuances of Java 8 Streams and explain these to those around you, then this course is for you.
  • Developers seeking an introduction to Functional programming and Lambda Expressions in Java 8