Java · Advanced level

Advanced level · Module 1 of 6 · 22 guided hours

Generics, Lambdas and Streams

Write reusable, type-safe code with generics, and process collections declaratively with lambdas and the Stream API.

Learning objectives

  • Write generic classes and methods with bounded types
  • Use lambdas, functional interfaces and method references
  • Build stream pipelines to filter, transform, group and summarise data

Topics

  • generic classes and methods
  • bounded types and wildcards
  • lambdas and functional interfaces
  • method references
  • Stream API: filter, map, reduce, collect
  • Collectors.groupingBy and Optional

Lessons

  1. Lesson 1 Generic Classes and Methods

    Write classes and methods that work with any type while keeping compile-time type safety.

    type parameter <T>bounded type <T extends Comparable<T>>wildcards ? extends / ? supertype erasure

  2. Lesson 2 Lambdas and Functional Interfaces

    Pass behaviour as values with lambdas and method references, using the standard functional interfaces.

    lambda expressionfunctional interfacePredicate / Function / Consumer / Suppliermethod reference

  3. Lesson 3 Stream Pipelines

    Process collections with streams: filter, map, sort, reduce and collect, and know when a loop is clearer.

    stream sourceintermediate operation (filter, map, sorted)terminal operation (collect, sum, count)laziness

  4. Lesson 4 Grouping, Summarising and Optional

    Group and summarise data with Collectors, and handle possibly missing values with Optional.

    Collectors.groupingBysummingInt / counting / averagingDoubleOptionalorElse / map / ifPresent

Practical activity

Rewrite a loop-heavy sales report as stream pipelines that group sales by region and month and report the top products, then compare readability and test results.

Expected outcomes

  • Reusable generic utilities
  • Concise, readable data processing with streams

Assessment

Practical: implement five reporting queries with streams over a provided data set; marked by unit tests and a short readability review.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.