naming methods and variables : Java Glossary
home N words local find no local find frame, full screen Google search web for topic jump to footer translate with Babelfish by Roedy Green ©1996-2008 Canadian Mind Products
Go to : punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)
naming methods and variables
You might find some of the suggestions for terrible names in the "How To Write Unmaintainable Code" section of the Java & Internet Glossary instructive.
Technical Requirements Interfaces
Meaningful Method Names Plurals
Hungarian Notation Links

Technical Requirements

Names of identifiers for classes, methods and names can in theory be arbitrarily long. They are limited only by the 32-bit 2 gigabyte addressing limit of Strings. In practice though, non-local names often end up inside class file which has its own limits which tend to based around 16-bit addressibility. The only restriction is they must start with a Java letter, upper or lower case. That list of Java letters includes _ and $, though $ should only be used for mechanically generated code since JavaC uses $ in constructing names for anonymous classes. If you are unsure what constitutes a Java letter use, Character. isJavaIdentifierStart( int ). The category casts a broad net, and includes all kinds of foreign alphabets. The rest of the identifier can also contain the digits 0-9.

Meaningful Method Names

One of the most time-consuming and often neglected coding tasks, is renaming methods and variables to give ever clearer intentions. The idea is to suggest in the name exactly what the method does, no more, no less. You also want to distinguish it easily from all similar (non-overloaded) methods. You have to balance the pain you cause forcing client code to rename against the potential for confusion during future maintenance. A tool like IBM’s VAJ takes out most of the pain. Most of this renaming work goes on in the early stages of code development before the first release of a class. You would be amazed how much renaming a method or variable helps you understand your own code. It greatly aids the composition process. It gives you better tools to think with.

If you can’t come up with a good name for a method, there is a good chance your method is not sufficiently unified, and you should repartition the work.

Hungarian Notation

If you use any variant of Hungarian notation where you put type information in your name, make sure you maintain it. If you change the type of the variable or method, you must globally rename it. Experiences with inaccurate Hungarian notation cause most maintenance programmers to detest detest all forms of Hungarian notation.

Local Variables

The conventions for single letter local variables date back to FORTRAN days. IntelliJ inspector enforces them.
int i, j, k, m, n
float f
double d
byte b
char c, ch
long l
String s, str

Interfaces

Interfaces are usually adjectives, e.g. Serializable, Externalizable. Classes that are related to each other should have names that are related e.g. BaseShape, CircularShape and RectangularShape.

Plurals

Arrays and Sets should have plural names. e.g.

CMP_homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.18] The information on this page is for non-military use only.
You are visitor number 7,271. Military use includes use by defence contractors.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/Mindprod website mirror)
http://mindprod.com/jgloss/naming.html J:\mindprod\jgloss\naming.html