Well, you might have heard about this word a lot but if you haven’t let me just give you a quick summary. Lambda expressions (or lambda functions) are essentially blocks of code that can be assigned to variables, passed as an argument, or returned from a function call, in languages that support high-order functions. They have been part of programming languages for quite some time. Some examples include Smalltalk, Lisp, Ruby, Scala, Python, and, more recently, Java and JavaScript. Here are some examples:
- Python:
square = lambda x: x**2
square(6) //-> 36
- Ruby:
square = lambda { |x| x * x }
square.(6) #-> 36
- JavaScript (fat-arrow functions):
var square = x => x * x;
square(6) //-> 36
Now coming back to where we were. So, from the above explanation you would have gotten an idea of what lambda expressions or lambda programming is and as you have read the title we are here to discuss some of the benefits of lambda programming which are:
- Conciseness
- Reduction in code bloat
- Readability
- Elimination of shadow variables
- Encouragement of functional programming
- Code reuse
- Enhanced iterative syntax
- Simplified variable scope
- Less boilerplate code
- JAR file size reductions
- Parallel processing opportunities
To get a full understanding of the benefits of lambda expressions in Java and how they provide conciseness and readability, just look at how functional interfaces, that is, an interface that only defines a single method, were implemented prior to lambda expressions. There were basically two approaches that could be used. One approach was to define a separate class that implements the interface, while the second was to use an anonymous inner class.
Single class approach to interfaces
Using a separate class to implement the Comparator interface example from a prior lambda functions article would looks as follows:

The benefits to this approach is the ability to share the new class among multiple code bases, so reuse is possible. The disadvantages to the single class approach? For starters, there is code bloat, as a whole new class is required to implement a single method. Furthermore, the logic is separated from the point in which it is needed, which will make troubleshooting and code maintenance more difficult in the future. To address the shortcomings of this approach, Java 1.1 introduced the concept of anonymous inner classes.
Benefits and drawbacks to anonymous inner classes
An anonymous inner class allows developers to define and implement a functional interface at the point in the code where it is needed. In the prior example, we needed to create a separate class named MyComparator. With anonymous inner classes, you don’t define a separate class, you simply implement the methods requires, thus the name anonymous. Here’s how the Comparator example looks when implemented using an anonymous inner class.

Anonymous inner classes are popular, and much preferred over creating separate implementing classes. They also allow for the implementing code to be written at the spot in which the code is used, which makes troubleshooting and long-term maintenance easier.
There are drawbacks to anonymous inner classes though. One major drawback is that the code does not look pretty. If anything, it looks bloated. Furthermore, the ability to reuse this code is muted, as there’s not way to invoke an anonymous inner class from outside of the code in which it is defined. And a more innocuous issue with anonymous inner classes is the peculiar variable scope they introduce directly within a class. Variables defined outside of an inner class do not employ the traditional rules pertaining to block scope within a Java class. As a result, it is easy to fall prey to a bug-inducing anti-pattern known as variable shadowing. This can create bugs that are very difficult to troubleshoot.