3. Functional Programming Paradigm
Functional programming is a programming paradigm in which we try to bind
everything in pure mathematical functions style.
It is a declarative type of programming style.
Its main focus is on “what to solve” in contrast to an imperative style where the main
focus is “how to solve”.
It uses expressions instead of statements.
Java – Object Oriented Programming
Java 8 – Functional Programming
Let’s c an example
4. Java 8
Oracle released a new version of Java as Java 8 in March 18, 2014.
It includes various upgrades to the Java programming, JVM, Tools and libraries.
Java 8 is the latest release for Java that contains new features, enhancements and
bug fixes to improve efficiency to develop and run Java programs.
It was a revolutionary release of the Java for software development platform
5. Functional Interface:
An Interface that contains exactly one abstract method is known as functional
interface.
It can have any number of default, static methods but can contain only one abstract
method.
The functional interface is used to support the functional programming approach,
lambda expression, and method reference as well.
6. Lambda expressions:
Lambda expression is also known as an anonymous function.
It is designed to provide the implementation of a functional interface.
Syntax
(list of arguments) -> { expression body}
1. list of arguments can be zero, one, or more.
2. expression body can have one or more statements.
Let’s c an example
7. Method Reference :
Method reference is used to refer method of functional interface.
It is compact and easy form of lambda expression.
Each time when you are using lambda expression to just referring a method, you
can replace your lambda expression with method reference.
Types of Method References
There are following types of method references.
Reference to a static method.
Reference to an instance method.
Reference to a constructor.
Advantages?
8. Streams API
A Java Stream is a component that is capable to perform internal operations of its
elements.
For example, it can iterate its elements itself.
A stream source can be a Collection, an array, or an I/O channel.
Java Example: Filtering Collection without using Stream
Java Stream Example: Filtering Collection by using Stream
Java Stream Example: Map Collection by using Stream
Java Stream Example : reduce() Method in Collection
Java Stream Iterating Example