Understanding the difference between method definition and method execution
For those new to programming, it may surprise you to know that there are two parts to having a method do something. Firstly, we must code the method (the method definition). This is similar to a bank machine on the street – it just sits there, doing nothing, waiting to be used. Secondly, we must execute the method (the method execution). This is similar to a customer “using” the bank machine. Remember that the main
method is the only method that is automatically executed by the JVM. Any other method calls have to be explicitly coded.
Now, let’s examine the method definition and method execution in turn.
Method definition
The method definition (declaration) is the method code itself - this is the block of code that is executed when the method is called. Figure 7.4 presents the syntax:
Figure 7.4 – The syntax of the method definition
In...