Understanding functions and methods as first-class citizens
Since its first release, Java has been an object-oriented programming language. Starting with Java 8, Java added support for the functional programming paradigm and continues to do so in Java 9. Functional programming favors immutable data, and therefore, functional programming avoids state changes.
Note
The code written with a functional programming style is as declarative as possible, and it is focused on what it does instead of how it must do it.
In most programming languages that provide support to the functional programming paradigm, functions are first-class citizens, that is, we can use functions as arguments for other functions or methods. Java 8 introduced many changes to reduce boilerplate code and make it easy for methods to become first-class citizens in Java and make it easy to write code that uses a functional programming approach. We can easily understand this concept with a simple example such as filtering a list...