Java Tutorial: Interfaces
Define interfaces, implement multiple interfaces, default methods, functional interfaces, and the Comparable/Comparable pattern.
Contracts for behaviour
Interfaces define what a class can DO — without saying HOW it does it. A `Printable` interface says "you can print yourself". Any class can implement it.
Unlike abstract classes, a class can implement **multiple** interfaces — solving Java's single-inheritance limitation. This is how Java achieves flexible, composable design.
What you'll learn in this Java interfaces tutorial
This interactive Java tutorial has 6 hands-on exercises. Estimated time: 20 minutes.
- Define and implement an interface — An interface defines method signatures — no body (unless using `default`). Classes `implement` the interface and provide…
- Multiple interfaces — A class can implement multiple interfaces — separated by commas:
- default methods — add to interfaces without breaking — `default` methods in interfaces have a body — they're optional to override.
- Comparable — natural ordering — `Comparable<T>` is a built-in interface for natural ordering. Implement `compareTo()` and `Arrays.sort()` / `Collections…
- Functional interfaces and lambdas — A **functional interface** has exactly one abstract method. You can use a lambda instead of an anonymous class:
- Build a payment system — Final challenge — no starter code.
Java Interfaces concepts covered
- Contracts for behaviour