On March 18, 2014, Oracle
launched the 8th
version of Java
. It was a major update after Java 6
.
There are majorly 5 types of programming languages
- Procedural Programming Language
- Functional Programming Language
- Scripting Programming Language
- Logic Programming Language
- Object-Oriented Programming Language
up to version 7
, Java was a pure Object Oriented Programming Language
but after Java 8
release provides support for Functional Programming
as well.
what is funcitonal programinig
Functional Programming
has 5 key principles:
- Pure functions:
Pure Functions operate and execute independently from the outside function, it contains only those operations which are essential to find the output.
- Immutability:
In Functional Programming
, the Inputs
are used as a reference only, but they are not modified. all the functions should always return the same output value for the same input values, no matter how many times they have been called.
- First-class functions:
Functions
have certain behaviours, such as functions can be overloaded with different types of parameters, and one or more functions can be passed as an input to another function, they can be overridden within the calling API as an anonymous function.
- Function Composition:
Simple or small functions will complete or execute small and simple tasks and Complex functions will complete or execute the big and complex tasks. Multiple small and simple functions can be joined together as per the requirement to create a complex function.
Lambda Functions
Lambda expressions introduced in Java 8 are more like anonymous functions, it has no name and is declared at the time of usage. it provides an easy way to create pure functions and first-class functions and provides immutability of input.
Oracle introduced a lot of new features in the release such as.
- Functional interfaces
- Lambda expressions
- Stream API
- Optional class
- Collectors class
- Method references
- Default methods
- Static methods in the interface
- Date Time API
let's understand them one by one.