Loading sub-menu...

Java Naming Standards and Guidelines

This document provides guidelines for naming classes in Java code. You can use them to help achieve code consistency amongst your development team. Having a naming standard is more important than the conventions it actually defines; you can always define your own if you disagree with ours. What's important is to achieve consistency amongst your development team. Having a written standard can also be helpful when new developers join the team.

Data Access Objects

Any class which accesses a database directly through JDBC is suffixed with the acronym 'DAO'. For example:

Java Class Name: UserDAO

Value Objects and Data Transfer Objects

A value object (VO) typically represents a simple object used to transfer data between subsystems. These are also sometimes referred to as Data Transfer Objects (DTOs). These objects do not have any behavior except for storage and retrieval of their own data (accessors and mutators). Any object that serves this function should be suffixed with the acornyms VO or DTO. For example:

Java Class Name: OntClassVO
Java Class Name: OntClassDTO

We like to use VO to represent objects that are specifically intended to be passed to the view layer for rendering and reserve the use of DTO for objects that are passed around in lower levels.

Interfaces

All Java interface classes should be prefixed with the character 'I'. For example:

Java Interface Name: IUser

Implementations

The common characters 'Impl' should not be used. A class with the same name as an interface is known to be an implementation of the interface by implication of its name similarity. Since the prefix of the interface is 'I', the two are differentiated. For example:

– Class 'IUser' is the interface.
– Class 'User' is the implementation.

Incorrect: User and UserImpl
Correct: IUser and User

Capitalization of acronyms in Java class names

When using an acronym in a Java class name, capitalize each letter in the acronym. For example, TO is a common acronym for "Transfer Object":

Incorrect: CacheDetailsTo
Correct: CacheDetailsTO

You might actually prefer to capitalize only the first letter of the acronym. We have learned, however, that capitalizing every letter of an acronym in Java class names is the most widely held convention amongst programmers. While it makes no difference in the functionality of your code, it is likely to be inconsistent with many of the dependencies you will use that were written by other developers.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.