Functional Programming is a paradigm that takes complex computation as the evaluation of mathematical functions (lambda expressions) which makes the code easier to understand, less complex, and reasonable to test. The original Java programming language is based on Von Neumann architecture.
Functional Programming works on four concepts in Java 8:
-
Lambda Expressions: Lambda expressions lets a function (method) pass as an input parameter for another function. Lambda function comprises two parts separated by a
‘->’. Parameter -> { function body } -
Functional interfaces: A functional interface has one abstract method ie. a method that has not been instantiated.
-
Optional class: Optional classes are container classes that include classes that either present (contains object) or not present (empty). Use java.util.Optional to create an optional class.
-
Stream API: Stream API processes a collection of objects that involves a process containing a data source, perform intermediate operations, and get a result.
Java is not a functional language but imperative. But to tone down certain complexities, with the advent of Java 8, a few aspects of functional programming were added. Also, not all concepts of functional programming solve real problems.
| Resource | URL |
|---|---|
| Functional Programming in Java | Link / Link |
| Optional Classes Crash Course | Link |
| Java Streams Tutorial | Link |