Skip to content

ropereraLK/Java-Functional-and-Stream-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Java Functional Programming & Stream API Training Roadmap

This is a 3-week hands-on training roadmap for mastering Java Functional Programming and Stream API. Designed for 2–3 hours/day of practice, progressing from basics to advanced concepts with mini-projects.


Week 1: Foundations of Functional Programming in Java

Goal: Understand lambdas, functional interfaces, method references, and core FP concepts.

Day 1–2: Functional Interfaces & Lambdas

  • Learn:

    • @FunctionalInterface
    • Lambda syntax (params) -> expression
  • Practice:

    • Implement Runnable, Comparator, and a custom functional interface.
    • Example: Calculator interface for add, subtract, multiply.

Day 3: Method References

  • Learn:

    • ClassName::staticMethod
    • instance::method
    • ClassName::new (constructor references)
  • Practice:

    • Convert existing lambdas to method references.

    • Example:

      List<String> names = List.of("Alice","Bob");
      names.forEach(System.out::println);

Day 4: Predicates, Consumers, and Suppliers

  • Learn:

    • Predicate<T> → test conditions
    • Consumer<T> → accept values
    • Supplier<T> → provide values
    • Function<T,R> → transform values
  • Practice:

    • Filter strings by length using Predicate
    • Generate random numbers with Supplier
    • Print values with Consumer

Day 5: Optional & Null Safety

  • Learn:

    • Optional<T> to avoid NullPointerException
  • Practice:

    • Wrap variables in Optional
    • Use ifPresent(), orElse(), map()

Day 6–7: Mini Project

  • Build a functional utility class with:

    • Filtering, mapping, aggregating, and null-safe methods.
  • Practice chaining functional interfaces.

  • Example:

    UserUtils.filterActiveUsers(users)
             .map(User::getEmail)
             .forEach(System.out::println);

Week 2: Stream API Basics

Goal: Process collections in a functional style.

Day 8: Creating Streams

  • Learn: stream(), parallelStream(), of(), Arrays.stream()

  • Practice:

    • Convert list/array to stream and print elements.

Day 9: Filter, Map, Peek

  • Learn: filter(), map(), peek()

  • Practice:

    • Filter even numbers, square them, print intermediate results.

Day 10: Reduce & Collect

  • Learn: reduce() → aggregate, collect() → gather results

  • Practice:

    • Sum, multiply, max, min
    • Collect to List, Set, or Map

Day 11: Sorting & Distinct

  • Learn: sorted(), distinct(), limit(), skip()

  • Practice:

    • Sort numbers descending
    • Remove duplicates from a list

Day 12: Grouping & Partitioning

  • Learn: Collectors.groupingBy(), Collectors.partitioningBy()

  • Practice:

    • Group Person objects by age
    • Partition even and odd numbers

Day 13: FlatMap & Nested Streams

  • Learn: Flatten nested collections

  • Practice:

    • Flatten List<List<Integer>> into List<Integer>
    • Flatten a List<Person> each having List<Address>

Day 14: Mini Project

  • Task: Build a data processor:

    • Input: List of Employees (name, dept, salary)

    • Output:

      • Employees per department
      • Highest salary per department
      • List of names with salary > 5000

Week 3: Advanced Stream & Functional Patterns

Goal: Apply FP & Stream API in real scenarios.

Day 15: Parallel Streams

  • Learn: parallelStream(), spliterator()

  • Practice:

    • Compare stream() vs parallelStream() performance on large lists

Day 16: Advanced Collectors

  • Learn: joining(), summarizingInt(), mapping(), toMap()

  • Practice:

    • Create comma-separated names
    • Count employees per department

Day 17: Combining Streams

  • Learn: Stream concatenation, Stream from Optional

  • Practice:

    • Merge two lists, filter, sort

Day 18: Functional Programming Patterns

  • Learn: Immutability, pure functions, higher-order functions

  • Practice:

    • Create pure transformation functions for lists

Day 19: Exception Handling in Streams

  • Learn: Wrap checked exceptions in lambdas

  • Practice:

    • Read file lines with Files.lines().stream() and handle exceptions functionally

Day 20–21: Capstone Mini Project

  • Task: Employee Analytics App

    • Input: List<Employee> (id, name, dept, salary)

    • Features:

      • Filter by salary range
      • Group by department and calculate avg salary
      • Find top 3 highest-paid employees
      • Flatten nested projects per employee
      • Produce summary report

Tips for Maximum Learning

  1. Use IntelliJ IDEA or Eclipse for functional shortcuts.
  2. Try to chain operations instead of writing loops.
  3. Keep a practice notebook of examples.
  4. Refactor imperative code to functional style wherever possible.
  5. Check JavaDocs for Stream API and Collectors – they have ready examples.

About

Java Functional and Stream API practice

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages