Tuesday, February 25, 2014

Java Code Conventions


Java Code Conventions

Sun has created a set of coding standards for Java, and published those standards in a document titled "Java Code Conventions".
  • Classes and interfaces:

The first letter should be capitalized, and if several words are linked together to form the name, the first letter of the inner words should be uppercase (a format is called as "camelCase").
For example:
Dog (Class)
Account
(Class)
PrintWriter (Class)
Runnable (interface)
Serializable
(interface)

  • Methods

 The first letter should be lowercase, and then normal camelCase rules should be used.
 For example:
getBalance
doCalculation
setCustomerName

  • Variables

 Like methods, the camelCase format should be used, starting with a lowercase letter. Sun recommends short, meaningful names.
For example:
buttonWidth
accountBalance
myString

  • Constants

 Java constants are created by marking variables static and final. They should be named using uppercase letters with underscore characters as separators.
For example:
MIN_HEIGHT
MAX_HEIGHT

No comments:

Post a Comment