Java Programming Style Guide

Indentation

Use three spaces for indentation to indicate nesting of control structures.

Rationale

Most programmers will standardize on 2, 3, or 4 spaces of indentation. For CS 110, three spaces works well: it is still noticeable even with the smaller font sizes used for printing yet not so large that line wrap becomes a major concern.

While it may seem easier to insert tabs in place of spaces for indentation, tabs are set inconsistently across computers and what may look perfect on your computer may appear staggered on someone else's computer if their tab settings do not match your own. By using spaces instead of tabs, indentation will be consistent across computers regardless of whether the tab setting is 2 or 8.

   public class HelloWorld
   {
   ...public void greetUser(int currentHour) 
   ...{
   ......System.out.print("Good");
   ......if (currentHour < AFTERNOON) 
   ......{
   .........System.out.println(" Morning");
   ......} 
   ......else if (currentHour < EVENING) 
   ......{
   .........System.out.println( "Afternoon");
   ......} 
   ......else
   ......{
   .........System.out.println("Evening");
   ......}
   ...}
   }
   
   Note: The period char (.) is used to show indentation