6.4. Variables and Parameters

No static variables [STATIC-VARIABLE: 2-20]

Do not create any static variables unless explicitly allowed by the assignment.

Instance variables must not be substitutes for parameters or local variables. [INSTANCE-VARIABLE: 2-20]

An instance variable should be used to remember a property of an object, and must have a meaning between method calls. If you create an instance variable, ask yourself what property of the object it stores. Do not use an instance variable as a local variable or as a way to avoid passing a parameter.

Do not change the same variable twice in one statement [DOUBLE-CHANGE: 1-2 points]

Do not write a statement that includes two explicit changes of a variable. For example, statement
  x = x++;
tries to change x twice.

Do not make a change that will surely not be seen [INVISIBLE-CHANGE: 1 point]

Do not use ++x where you really mean x+1. Do not change the value of a local variable when the changed value cannot possibly be looked at again. For example, do not write
  return test(++x);
since the altered value of x cannot possibly be looked at. Instead, write
  return test(x+1);

Do not store a value into a local variable just to return it [RETURN-VARIABLE: 1 pt]

If y is a local variable, do not write
  return y = x + 1;
which stores the value of x + 1 into variable y, and then immediately returns that value. There is no point to variable y. Just write
  return x + 1;

Do not change the value of a parameter. [CHANGE-PARAM: 1-5 points]

Do not change the value of that parameter anywhere in the method body. For example, method next defined by
  static int next(int n)
  {
    while(!isgood(n))
    {
      n++;
    }
    return n;
  }
takes parameter n. It changes the value of n in the method body. Do not do that.