Linggo, Hulyo 28, 2013

Java Coding Standards

Sun estimates that on a typical lifetime of codes, creation and testing of codes consumes only 20%, and the remaining 80% efforts will go to maintenance and enhancement. Also, hardly any software is maintained for its whole life is maintained by its author. Thus, Sun set standard convention that they follow and encourage other Java programmers to improve readability of the codes of software, allowing programmers to understand new code easily (that others have written),  and reduce the effort focused on testing, maintaining and enhancement of any piece of code.


  1. Classes and Interfaces
    Classes names should be nouns.  For one worded classes, first letters should be capitalized. If two or more words are linked together to form the name, the first letter of the succeeding words should be capitalized (Billing + File = BillingFile).
    Examples:
     Header  
     Details  
     Flowers  
     BillingFile  
    
    For Interfaces, names should be adjectives.
     Serializable  
     Runnable  
    

  2. Methods
    Method names should be in verb-noun combination. Format should be in camel case (camelCase) where first word should be in lower case and the first letter of the succeeding word/s should be in capital.
    Examples:
    Header  
    getSum
    convertFile
    formatNumber
    computeBillingAmount 
    

  3. Variables should also be in camelCase
    Examples:
    frameHeight
    billSummary
    accountName
    temp
    

  4. Constants - Java constants are variables marked as static and final. They should be named in uppercase with underscore as separators.
    Examples:
    ENCRYPT_KEY
    MIN_WIDTH
    MAX_HEIGHT
    ITERATOR 
Source: Java Code Convention, Sun Certified Programmer for Java 6 Study Guide by Kathy Sierra and Bert Bates

Walang komento:

Mag-post ng isang Komento