Step 5. Step Into a Method Call

previous step next step


The Step Into command behaves similarly to Step Over except that if the next line of code to be executed calls a method, then Step Into descends into the method. This allows you to execute the method line-by-line in the debugger.

If you've followed the tutorial exactly as directed in this tutorial, your program will be halted just before executing the line:

          input = new inputBox(tank);

Since we know a bug that we're trying to fix, let's focus on that bug first. We know that the number of fish created was incorrect, so we will want to set a breakpoint and run the debugger until we reach that point in the main method. Scroll through the main method until you find the call to the addFish() method. Set a breakpoint at this line. Your window should look similar to this.

Press the Resume button. This will run the debugger until it reaches the newly set breakpoint. You will need to move or minimize any windows that obscure the input dialog box.

Enter 3 fish, 2 piranha and 5 food centers as you did before.

Next, press the Step Into button. This will cause the debugger to descend into the code for the addFish() method. You should see the following:

The debugger is now showing the code of the addFish() method. The first line of the addFish() method is highlighted. This indicates that the addFish() method has not yet been executed.

If we had chosen Step Over instead of Step Into , the method would have been executed in its entirety and we would not have been given the opportunity to fix the addFish() method. With Step Into, you descend into any method that is called and can then watch individual lines of the method execute.

If you do not have access to the source code or you are positive that the bug is not being caused by a specific method, choose the Step Over button. If you will need to trace code in great detail, you should choose the Step Into button.

Note: You will not be able to Step Into code for which you do not have access to the source.

It is very useful to have both Step Into and Step Over commands. You will find that you will you use both frequently.

We must now trace the execution of this method until we discover why it is adding one too many fish to the simulation. Before we continue using Step Over or Step Into to follow the execution of this method we want to make sure that the value of the quantity parameter is correct.

Action!Provide me with a screenshot of your environment now.

Continue with the tutorial to see how to do this.


previous step next step