Just few days back, I stumbled upon an article in DZone about implementing Lazy Evaluation in your current program. Those of you who are quite acquainted with Java 8 Higher Order Functions or Lambda Expressions, might have already used stream based Higher Order Functions which facilitates us with the opportunity for Lazy Evaluation.
I would like to focus on how to convert your current code to evaluate the functions lazily.
What is Lazy Evaluation?
Lazy evaluation can be considered as the computation is delayed util it is actually needed. Lazy evaluation can lead to reduction in memory footprint, since values are created when required.
The following example is slightly modified in accordance with more readability.
The client application: