5.8.3. Procedures

Some methods only perform actions and do not return any useful results. I will call such methods procedures.

The return-type of a procedure should be void. For example,

  static void printHeading()
  {
    System.out.printf("Here is the input.\n");
  }
defines procedure printHeading, with no parameters. Notice that, because the return-type is void, there is no return statement. The procedure returns when it reaches the end of the body.

If you want to include an explicit return in a procedure, write

  return;
No result is indicated because a procedure does not have a result.


Using procedures

Use a procedure in a statement. For example,

  printHeading();
performs the body of printHeading.


"Void" methods

Many people call a procedure a void method. I prefer not to use that term because the method is not in any sense void. Outer space is (almost) void. You can write void across a check to render it not usable. A procedure simply does not return an answer.