Signpost with the words Consumer and Supplier

Your guide to the standard Java functional interfaces

Last week I wrote about functional interfaces and how to use them as targets for lambda expressions. I showed you how we create a variable of a functional interface type and assign a lambda expression to it. Today I want to help you make sense of the set of standard functional interfaces.

Continue reading
functional interfaces in java

Functional Interfaces

You’ve probably heard of a functional interface before, often in the same breath as lambdas. What are functional interfaces, and why are they used with lambdas?

Lambdas and functional interfaces go hand in hand in Java.

A functional interface is simply an interface that has a single abstract method. Before Java 8, they were referred to as SAM interfaces.

Why are these interfaces so important that they have their own term? Two reasons:

Continue reading
Scale with oranges on one side and apples on the other side

Comparable vs Comparator

How do we compare apples with oranges? Or even apples with apples, for that matter? Do we compare based on size or colour or shape or sweetness?

We often need to compare objects. Sorting, for example, is based on comparison according to some criteria. So it is important to understand the difference between Comparable and Comparator. Continue reading

Drawing of a cannon

Canonical classes in Java

You may have heard of canonical classes before. But what are they actually?

No, they’ve got nothing to do with cannons – I just chose that image for fun. In computer science, the term “canonical” means conforming to well-established patterns or rules.  (The word canonical is from Latin and means “according to rule” – a meaning applied to religion during the Middle Ages.)

Continue reading