Functional Programming

  • What is Functional Programming?
    Paradigm that treats computation as the evaluation of mathematical functions, and avoids changing-state and mutable data.
    Calling a Function with the same arguments always produces the same result.

  • What is a Lambda Expression?
    It is a function which can be created without belonging to any class.
    It is an Anonymous Function: without name and without being bounded to an identifier.

  • What is a functional interface?
    It is a SAM Interface (Single Abstract Method Interface). Enforces the rule of Single Responsibility; they can be marked with @FunctionalInterface.
    Lambda expressions can be used to represent the instance of a functional interface.

  • Where are Lambda Expressions used?
    As event listeners or in Functional Programming with Java Stream API.

  • Java Stream API
    Provides a functional approach to iterating and processing elements of a Collections.

  • What is a Java Stream?
    A Stream is a sequence of objects that supports various methods which can be pipelined to produce a desired result.
    • it takes input from Collections, Arrays, I/O.
    • don’t change the original data structure, they only provide the result.