A programming paradigm where functions are first-class citizens - treated like values.
In Java, functional programming was introduced with Java 8, enabling:

  • more concise, expressive code,
  • declarative data processing (Streams),
  • use of lambda expressions, functional interfaces and method references.

Functional vs Imperative Style

Imperative (Old School)Functional (Modern Java)
β€œHow to do it” - step-by-step”What to do” - describe the operation
Uses loops, conditionalsUses functions like map(), filter()
VerboseConcise, expressive
// Imperative
List<String> result = new ArrayList<>();
for (String name : names) {
    if (name.startsWith("A")) result.add(name);
}
 
// Functional
List<String> result = names.stream()
    .filter(n -> n.startsWith("A"))
    .collect(Collectors.toList());

Key Functional Concepts in Java

ConceptPurpose
Lambda ExpressionsInline functions (no boilerplate)
Functional InterfacesInterfaces with a single abstract method
Streams APIFunctional-style data processing
Method ReferencesCleaner alternative to lambdas
OptionalAvoiding nulls in a functional way

Characteristics of Functional Code

  • No side effects.
  • Pure functions.
  • Immutability.
  • Higher-order functions (accept or return other functions).

Tip

Be ready to:

  • explain what FP is and how Java supports it since Java 8,
  • show for-loop β†’ stream().filter() conversion,
  • mention lambda expressions and Streams API as key tools.

Parent: _Multithreading