- Interface default methods and static methods
1. Why Default Methods? Imagine a city planner who designed a road system 20 years ago. Thousands of buildings were constructed along those roads. Now the city needs bike lanes. The planner cannot tear down every building and start over — the city must add bike lanes without breaking the existing…
- Functional Interfaces
1. What is a Functional Interface? Imagine a contract that says: “You must do exactly one thing.” It does not care what that thing is — it could be filtering data, transforming text, printing output, or computing a value. But the contract only has one obligation. That is a functional interface in…
- Method References
1. What Are Method References? Imagine you are giving someone directions. You could say: “Walk to the kitchen, open the drawer, grab a knife, and cut the bread.” Or you could simply say: “Cut the bread” — because the person already knows the steps. A method reference is that shorter instruction.…
- Lambda Expression
1. What Changed in Java 8? Before Java 8, Java was a purely object-oriented language. Every piece of behavior — sorting a list, filtering a collection, handling a button click — had to be wrapped inside a class. If you wanted to pass a comparator to Collections.sort(), you created an anonymous…
- Iterator Pattern
Introduction The Iterator Pattern provides a way to access elements of a collection sequentially without exposing its underlying representation. Whether the data lives in an array, a linked list, a tree, or a paginated API, the iterator gives clients a uniform interface to traverse it: hasNext()…