Style Guide

The following are things which are considered "good style" when writing programs in this class and in Java. You are responsible to keep an eye on this section. Once something is added to the list of "good style" failure to follow this will likely result in deduction of one or more points on programming assignments.

Universally Accepted Java Style

Things on this list are things which are contained in just about any Java Style guide at which you look. Things on this list are likely to be emphasized by just about any Java programmer you meet.

  • Java Doc
    • /**
    • *
    • * Class :ClassName
    • * Comments :Any comments about the class including its purpose
    • *
    • * @author Your Name
    • * @version year-mo-dy
    • */
  • More Java Doc
  • * @parm parmName Description
  • * @return Description
  • Comments can be inline and start with //
  • Constants are declared in caps
  • Use proper indention to make the code more readable.
  • Inherent methods can only become more open, ie. private->public, protected->public

"Schafer Style"

Things on this list are things about which I feel strongly but for which there isn't a single agreed upon style solution. For the purposes of this class you should follow these guidelines although you may be told differently if you get a job programming Java.

  • When creating a class or method always put the opening { under the class/method name.
  • All brackets must line up.
  • Role of the constructor is to initialize the instance variables (declare all int variables to zero on their own line, and all the referential data types to null).
  • All instance variables must be private
  • Build .java files as 1) Instance Variables (which are always private) 2) Constuctors 3) Methods
  • Always use a double OR (||) or a double AND (&&) when constructing a boolean statement.
  • For referential data types use the .equals() instead of "==" (i.e String; name.equals("Schafer")) (Note from Dr. Schafer - this isn't a style thing. This is the way Java works. If you want to test object equality instead of name equality you must use .equals(). )
  • Never use — if (boolean) then return true;
  • Use — return boolean
  • Especially never use — if(boolean == true) then return true; NO NO NO!!!
  • When working with the 6 types of inheritance don't use Limitation and Construction as these types of inheritance break the substitutablity of the child class for the parent or Super
  • When you have a Helper method or an inner class they are always private!
  • Only use Vectors if you are going to us Threads Vectors are made to use threads if you are not using threads you NEED to use an ArrayList instead.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License