Best Practices >> Core Java


Naming Conventions in Java


When writing programs in the Java language, there are a set of standard conventions which should be followed. These are followed in almost all kind of projects. Beginners in Java language are not used to utilizing the naming conventions but as one writes code in modern day IDE’s these naming practices become a habit.

Naming Conventions List

Class Naming
1) The class and interface names should start with Capital letters and each character signifying a part of name should also be in capital. A few examples of good class names is:
PortalManager
LDAPHelper

Package Naming
2) The naming convention for package names says that they should start from the reverse of the domain name of your company. So if a Java based product is being created for company “MyCompany”, following package names should be used:
com.mycompany.product.helper.StringHelper
com.mycompany.product.controller.WebServiceController

Do note that all characters in the package names are in small letters.

Variables Naming
3) The variables should have a naming convention of
a) The first letter should be small letter
b) Every word in the variable names should start with a capital letter
Some examples of variable naming convention are:
imageHolder
hitCounter
latestHitCounter

Method Naming
4) The method names also follow the same convention as the variables which is starting with small letter and every other word staring with Capital letter.e.g.
checkCardValidity()
addOrder()

Constants Naming
5) The constants which are declared as public static final in Java should have all letters as capital and the words within the constant should be separated by _(underscore) character as:
FILE_SEPARATOR
PROPERTIES_FILE_PATH

Besides the above listed naming standards, some developers make use _(underscore) character to start the variable names which is also acceptable.

One should keep in mind that the same naming conventions should be used across the Java application so that those maintaining the application get familiar with the coding conventions being used in the project.

Other Java Tutorial
Singleton Inheritance and Serialization
Design Patterns in Java
Combining Singleton and Serialization in Java
Inheritance Checklist

Leave Comment