for
loop, or the values of the parameters passed in a method call.
When you pause your program while debugging, you can examine the values of instance variables, local variables, properties, method parameters, and array items.
Data evaluation occurs at the level of expressions. An expression consists of constants, variables, and values in data structures, possibly combined with language operators. In fact, almost anything you use on the right side of an assignment operator can be used as a debugging expression.
JBuilder has several features enabling you to view the state of your program, which are described in the table below.
Feature | Enables... |
---|---|
Loaded classes and static data view | Viewing classes currently loaded by the program, and the static data, if any, for those classes. |
Threads, call stack and data view | Viewing the thread groups in your program. Each thread group expands to show its threads and contains a stack frame trace representing the current method call sequence. Each stack frame can expand to show data elements that are in scope. |
Data watches view | Viewing the current values of variables that you want to track. A watch evaluates an expression according to the current context. If you move to a new context, the expression is re-evaluated for the new context. If it is no longer in scope, it cannot be evaluated. |
Evaluate/Modify dialog box | Evaluating expressions, method calls, and variables. |
ExpressionInsight | Viewing the values of expressions. |
Static variable display
Static variables are displayed in the Loaded classes and static data view. When you expand the tree of loaded classes, all static variables defined for a class and their values are displayed. You can use the right-click menu to set watches on these variables, change values of primitive data types, or toggle the base display value.
Local and member variable display
Local and member variables are displayed in the Threads, call stacks, and data view. When you expand a thread group, a stack frame trace representing the current method call sequence is displayed. To display member variables, when you are in the class itself, expand the this
object. When you expand that node, you see all of the variables that are members of that class and the instantiation that you are working through. Grayed-out elements are inherited.
You can then use the right-click menu to set watches on these variables, and, if the variable is an array, create an array watch and determine how many array elements will display in the view. You can also create a watch for the this
object.
You can directly edit the value of a string or any primitive data type, including numbers and booleans, by right-clicking and choosing Change Value. (This is a feature of JBuilder Professional and Enterprise.)
Changing variable values
To change the value of a variable,
To change the display base of a numeric variable, right-click and choose Show Hex/Decimal Value. This command is a toggle - if the value is displayed in hex, it will display in decimal and vice versa.
Changing object variables
Object variables can be cut, copied, and pasted into other objects by using the Cut, Copy, and Paste commands on the right-click menus. If an object is pasted into another variable, both variables will point to that same object. (The Cut, Copy, and Paste commands are features of JBuilder Professional and Enterprise.)
Changing variable array values
You can change the value of an array element by right-clicking on the element you want to change and choosing Change Value. See the section called "Changing data values" for more information.
You can also change how the array is displayed. You can view the details of the array by expanding it. However, there might be so many items displayed that you'll have to scroll in the view to see all the values. For easier viewing, you can reduce the number of items shown with the Adjust Range dialog box. By default, only the first 50 elements of an array are displayed.
To reduce the number of array elements displayed,
You can also hide or display a null value in an array variable. This is useful when debugging a hash-map object. To enable this feature, right-click an array of type Object
and choose Show/Hide Null Value. (This is a feature of JBuilder Professional and Enterprise.)
Watch expressions that return an object or array value can be expanded to show the data elements that are in scope. For example, if you set a watch on a this object, or on a single object, the watch can be expanded. However, if you set a watch on a primitive value, the watch can't be expanded since it's a single item. The grayed-out items in the expanded view are inherited.
You can set two types of watches:
Named variable watches
A named variable watch is added on a name - as you move around in your code, whatever variable has the name you selected in the current context will be the one evaluated for the watch. If no variable has the name you select, the debugger will display the following message in the Data watches view:
variable name = <is not in scope>
To add a named watch, use the Add Watch dialog box. To display this dialog box,
Scoped variable watches
A scoped variable watch watches the variable in the scope (or context) in which you created the watch. As you move around in code, only the specific variable's value will be displayed. Scoped variable watches are features of JBuilder Professional and Enterprise.
If the scoped variable watch expression is not in scope, the debugger will display the following message:
variable name = <is not in scope>
When the expression is in scope, the debugger will display its value.
To add a scoped variable watch, choose the variable you want to watch from the Threads, calls stacks, and data view. Then, right-click. The menu allows you to add a scoped watch for the selected type of variable, including:
Watch types | Display | Description |
---|---|---|
Field watch |
![]()
"addResult"DebugTutorial.Frame1.this.addResult: |
The field being watched, addResult, is a primitive type. It is in DebugTutorial.Frame1. Its value is 68.0. |
Local variable watch |
![]() "valueOneDouble"valueOneDouble: |
The local variable being watched is valueOneDouble. It is defined as a Double object. |
Object watch |
![]() "DebugTutorial.Frame1"<reference>DebugTutorial.Frame1=
|
The object being watched is DebugTutorial.Frame1. The object expands to show data members. |
this watch |
![]() "this" this:{DebugTutorial.Frame1@353} |
The current instantiation of DebugTutorial.Frame1. The object expands to show data members for the current instantiation. |
Array watch |
![]()
"valueOneText"<reference>char[]=char[2]
| The array being watched is called valueOneText. It contains two array elements. |
Array component watch |
![]()
"[0] = '3'
| The first element of the array valueOneText. It contains the value '3.' |
To add an object watch,
A this object watch watches the current instantiation of the selected object.
To open the Evaluate/Modify dialog box, choose Run|Evaluate/Modify.
To evaluate an expression, enter the expression in the Expression field. If the expression is already selected in the editor, it is automatically entered into the Expression field. Then, click the Evaluate button. You can use this dialog box to evaluate any valid language expression, except expressions that are outside the current scope. If the result is an object, note that the contents of the object are displayed.
This is a feature of JBuilder Professional and Enterprise.
The results of a method call can also be evaluated. To evaluate a method call, enter the method and its parameters in the Expression field of the Evaluate/Modify dialog box. Click Evaluate.
In this example, the method return value evaluated to true.
This is a feature of JBuilder Professional and Enterprise.
You can change the values of variables during the course of a debugging session to test different error hypotheses and see how a section of code behaves under different circumstances.
When you modify the value of a variable through the debugger, the modification is effective for that specific program run only - the changes you make through the Evaluate/Modify dialog box do not affect your program source code or the compiled program. To make your change permanent, you must modify your program source code in the editor, then recompile your program.
To modify the value of a variable, enter:
variable = <new value>
in the Expression edit box. The debugger will display the results in the Result display box. Note that the result must evaluate to a result that is type compatible with the variable.
You can also modify the value of a variable using these steps:
The expression in the Expression input box or the new value in the New Value box needs to evaluate to a result that is type-compatible with the variable you want to assign it to. In general, if the assignment would cause a compile-time or runtime error, it's not a legal modification value.
For example, assume that valueOneText
is a String
object. If you enter:
valueOneText=34
in the Expression input field, the following message, indicating a type mismatch, would be displayed in the Results field:
incompatible types; found int; required java.lang.String
You would need to enter:
valueOneDouble="34"
in the Expression input field in order for the expression to be set to the new value.