Java Syntax Style Rules

 

Why are Coding Style Rules Important?

Coding Style Guidelines

  1. Avoid "The Blob".
    "The Blob" is what happens when a lot of complex code is put into one class, potentially all within one method. If code is complex, break up it up into several classes and/or methods.

  2. Use comments
    Put a comment above every class and non-trivial method. Ideally, javadoc comments (beginning with /** and ending with */) should be used for all classes, methods, and variables that are not private.

  3. Identifier Naming Conventions
    Kind Par-of-Speech Identifier Examples
    Variable
    noun
    sum, intialSpeed, firstName
    Constant
    noun
    SPEED_OF_LIGHT, PI
  4. Number of statments per line
  5. Spacing Conventions

  6. Indent properly and keep the length of all lines <= 80 characters
  7. Choose a style for curly braces and stick to it within a source file/package.
    The two most common ways of using curly braces are:
  8.   if (x == y) {  	
    	statements 
      }	
      OR 
      if (x == y)  	
      {  	   
     	statements 	
      }   
      
  9. Methods

  10. Classes

"Official" Java Coding Conventions from Sun

Important about style rules