Inspecting variable values

Now let's step over a few statements till we are in the while loop to create course objects from the data returned by the result set. In the top-right window, you will find the Variables view, which displays variables applicable at that point of execution:

Figure 6.10: The debugger paused at breakpoint

You can inspect variables in the previous method calls too by changing the selection in the Debug tab: click on any previous method call (stack frame) and the Variables view will display variables that are valid for the selected method. You can change the value of any variable, including values of the member variables of the objects. For example, in Figure 6.8, we can change the value of the course name from "Machine Learning" to "Machine Learning - Part1". To change the variable value, right-click on the variable in the Variables view and select Change Value:

Figure 6.11: Changing the variable's value during debugging

You don't have to go to the Variables view to check a variable's value every time. There is a quick way: just hover the cursor over the variable in the editor and Eclipse will pop up a window showing the variable's value:

Figure 6.12: Inspecting the variable

You can also right-click on a variable and select the Inspect option to see the variable's values. However, you cannot change the value when you select the Inspect option.

If you want to see the value of a variable frequently (for example, a variable in a loop), you can add the variable to the watchlist. It is a more convenient option than trying to search for the variable in the Variables view. Right-click on a variable and select the Watch option from the menu. The Watch option adds the variable to the Expressions view (its default location is next to the Breakpoints view at the top right) and displays its value:

Figure 6.13: Inspecting a variable

The use of the Expressions view is not limited to watching variable values. You can watch any valid Java expression, such as arithmetic expressions, or even method calls. Click on the plus icon in the Expressions view and add an expression.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.76.204