Interface naming in Java
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
In Java, interfaces are a fundamental concept in the realm of object-oriented programming, serving as a blueprint for classes. They define a set of methods that a class must implement, making interfaces pivotal in ensuring a formal contract for behavior. Given their significance, naming interfaces judiciously is crucial not only for code understandability and maintainability but also for promoting effective communication among developers.
Key Principles for Naming Interfaces
- Clarity and Intentionality: An interface should have a name that clearly communicates its purpose or the behavior it encapsulates. This name should be a noun, noun phrase, or an adjective describing the class's capability.
- Consistency: Maintaining consistency with the naming convention across a project or a codebase aids in reducing the learning curve for new developers and enhances code navigability.
- Use of Descriptive Names: Interface names should be descriptive yet concise. They should avoid ambiguity and be able to tell the developer what the set of methods primarily represent.
- Prefixing with 'I' - A Debated Convention: In some coding standards, particularly in environments influenced by .NET, interfaces are often prefixed with 'I' to distinguish them from classes. For example,
IReadable. However, in the Java community, this practice is less prevalent. Java developers generally prefer to use descriptive names without prefixes, relying on context and package structure to differentiate between interfaces and implementing classes. - Suffixes like 'able' or 'ible': When an interface is used to describe a capability, a suffix like
-ableor-ibleis commonly used. For example,Runnable,Cloneable, andReadable.
Examples of Interface Naming
Java’s standard library provides multiple instances of well-named interfaces that follow these conventions:
List: Describes a collection that orders elements and allows positional access.Readable: Provides a reader method that attempts to read characters into a specified buffer—indicating the ability or capability.
When to Use Interfaces
Interfaces are not simply about abstract methods but about defining roles, capabilities, and general contracts about what objects can do. They should be used when:
- You expect that unrelated classes would implement your interface. For example, both a
Carand aBoatmight implement aVehicleinterface if they share methods likestart()andstop(). - You want to specify the behavior of a data type, but are not concerned about who implements its behavior.
- You want to take advantage of multiple inheritance of type.
Naming Conventions: Case Studies and Their Impact
Good interface naming can simplify understanding the design of a software system by making interfaces and their intended implementations naturally readable. For instance, changing an abstract class name to an interface name from DataHandler to DataManageable or DataProcessor could make it clearer that the interface declares functionality for any data handling mechanism, not a specific implementation.
Summary Table
Below is a table summarizing the key points discussed:
| Aspect | Description |
| Principle of Naming | Clear, intentional, descriptive, and consistent. |
| Common Suffixes | -able, -ible (when describing capabilities). |
| Prefix Convention | Usually avoided in Java (contrary to other languages). |
| Examples from Java SDK | List, Runnable, Readable, Map, etc. |
| Usage of Interfaces | Defining roles, capabilities, and contracts. |
Additional Considerations
- Avoiding Interface Pollution: Not every set of methods deserves an interface. Interfaces should be meaningful and should correctly abstract a concept that might have multiple differing implementations.
- Tool Support: Modern IDEs and static code analysis tools can help by providing naming suggestions based on the functionality of the interface.
Interface naming, when done right, is not just a coding standard but a potent tool for effective communication and clean, maintainable code architecture. Developers are encouraged to think deeply about the names they choose, as these choices significantly impact the readability and future usability of the software.
Related reading
- Interface vs Abstract Class (general OO)
- Interoperating with Django/Celery From Java
- Interrupt a sleeping Thread
- Intersection and union of ArrayLists in Java
- ''Invalid bean definition'' when migrating Spring Boot 2.0.6 to 2.1.0 with EvaluationContextExtensionSupport and custom PermissionEvaluator
- Invalid character found in the request target in spring boot
- Invalid signature file when attempting to run a .jar
- Invoking a static method using reflection

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.