Java Naming Style Conventions

 

Why Naming Styles?

·         By following the Java naming style conventions your code will not only look like Java, it will help you and others in reading and understanding your code.

·         For the conventions to work, every person writing software must conform to the conventions.

General Convention

·         As a general convention, avoid the use of abbreviations except where the abbreviation is more common than the full name as in: HTML, URL, gpa, sin, cos, etc.

Class and Interface names

·         These should be nouns or noun phrases, with the first letter of each word capitalized, and all other letters in lower case. For example.

Frame
Dictionary
MenuBar
SecurityManager
 

Method names

·         These should be verbs or verb phrases, with the first letter of each word except the first capitalized, and all other letters in lower case. For example,

getSize
setSize
show
isVisible
toUpperCase
 

Field names that are not final

·         Should be nouns, noun phrases, with the same capitalization as for method names. For example,

position
firstName
bytesTransferred
 

final field names (i.e., constants)

·         A sequence of one or more words in all uppercase, with components separated by underscore "_" characters. For example,

PI
MAXIMUM_VALUE
NUMBER_OF_STUDENTS
 

Local variables and parameters

·         These are similar to non-final field names.  They should be short, yet meaningful.  For example,

   age
   circleArea
   xPosition

·         One-character local variable or parameter names should be avoided, except for temporary and looping variables.  Conventional one-character names are: