Lectures
 

Suggested Java Naming Conventions

ITEM NAMING CONVENTION EXAMPLE
Arguments / parameters Use a full English description of the value or object being passed, prefixing the name with 'a' to distinguish it as an argument aCustomer, aAccount
Attributes / fields / properties
(primitive data variables)
Use a full English description of the attribute, with the first letter in lowercase and the first letter of any nominal word in uppercase. firstName, lastName, warpSpeed
Boolean attributes and Boolean getter methods Follow the naming convention for attributes, except prefix the name with the word 'is'. isStudent, isStaff()
Classes Use a full English description, and capitalize the first letters of all words. Customer, SavingsAccount
Components / widgets Use a full English description that describes what the component is used for with the type of the component concatenated at the end. okButton, customerList, fileMenu
Final static attributes
(constant)
Use all uppercase letters with the words separated by underscores.  A better approach is to use final static getter methods because it greatly increases flexibility. MIN_BALANCE, DEFAULT_DATE
Loop counters It is generally acceptable to use the letters 'i,' 'j,' 'k' or even the word 'counter' i, j, k, counter
Methods Use a full English description of what the method does, starting with an active verb whenever possible, with the first letter in lowercase openFile(), addAccount()
Setter and Getter Methods Prefix the name of the attribute being accessed with 'set' or 'get.' setFirstName(), getFirstName()

Thanks to Scott Amber at Software Development Magazine for the guideline.

Home | Syllabus | Lectures | Assignments | Coding Conventions | Links