Imperative vs. Functional

Description

In imperative programming we control not only what to do but also how to do it.

For example, when using imperative programming to sum integers in a list. We have to decide how to iterate each element in the list. We can use for loop, for-each loop, or we can get an Interator object from list and use while loop. Then we also have to do the sum.

In declarative programming we just need to tell what to do, the how part is handled by the system itself.

Collections support imperative programming whereas streams support declarative programming.

The Streams API supports the functional programming by using lambda expression.

What operations we want to perform on the stream elements are done typically by passing a lambda expressions.

Operations on a stream produce a result without modifying the data source.





















Home »
  Java Streams »
    Tutorial »




Java Streams Tutorial