Purpose of this post is to provide a glimpse of the new features included in Java 8 that shift this language towards a more Functional Programming paradigm. But before, let’s define what we understand for Functional Programming (FP). Functional programming key characteristics include:
Higher Order Functions Pure Functions and Immutability Tail Call Recursion Higher Order Functions for a FP language means that functions are considered first class citizens, allowing the programmer to use them as any other value the language defines, for example, a Function value:
It’s been a little more than a year since Java 8 was released (2014/03/18) and you might think that it’s a little too late for a What’s new in post. In fact latest public update available is 8u40, so let’s review not only what was initially included in Java 8, but what else has changed during this first year, up to release 8u40.
Lots of changes were included in the initial Java 8 release, being probably the most notable of them, in my opinion (feel free to disagree, looking forward to discussions):
Function composition is one the key features (among others) of functional programming. Programming languages that offer higher order functions as a feature can potentially use function composition. But, still, programmers need to be aware of some key concepts to successfully apply this pattern in our code.
Function composition, as defined on Wikipedia, is an act or mechanism to combine simple functions to build more complicated ones. In other words, we can define new functions, equivalent to the result of chaining a set of given functions, so the input of function i is the output (or result) of function i-1.