Methods revisited
This figure probably roughly sums up where our understanding of methods is at the moment:
As we can see in the previous figure, there are still a couple of question marks around methods. We will completely take the lid off of methods and see how they work, and what exactly the other parts of the method are doing for us later in the chapter. In Chapter 9, Object-Oriented Programming, we will clear up the last few parts of the mystery of methods.
So, what exactly are Java methods? A method is a collection of variables, expressions, and control flow statements bundled together inside an opening curly brace and closing curly brace preceded by a name. We have already been using lots of methods, but we just haven't looked very closely at them yet.
Let's start with the method structure.
The method structure
The first part of a method that we write is called the signature. Here is a hypothetical method signature:
public boolean addContact(boolean isFriend, String name)
If we add an opening...