Evaluating variables in Java programs

There are two ways to evaluate a variable when a program stops running at a breakpoint or step.

  • Option 1: Enter EVAL VariableName on the debug command line.
  • Option 2: Put the cursor on the variable name in the displayed source code and press F11 (Display variable).
Note: You can also change the contents of a variable by using the EVAL command. For more information about the variations of the EVAL command, see WebSphere® Development Studio: ILE C/C++ Programmer's Guide, SC09-2712 and online help information.

When looking at variables in a Java™ program, note the following:

  • If you evaluate a variable that is an instance of a Java class, the first line of the display shows what kind of object it is. It also shows an identifier for the object. Following the first display line, the contents of each field in the object displays. If the variable is null, the first line of the display indicates that it is null. Asterisks show the contents of each field (of a null object).
  • If you evaluate a variable that is a Java string object, the contents of that string displays. If the string is null, then null displays.
  • You cannot change a variable that is a string or an object.
  • If you evaluate a variable that is an array, 'ARR' displays followed by an identifier for that array. You can evaluate elements of the array by using a subscript of the variable name. If the array is null, then null displays.
  • You cannot change a variable that is an array. You can change an element of an array if it is not an array of strings or objects.
  • For variables that are arrays, you can specify arrayname.length to see how many elements are in the array.
  • If you want to see the contents of a variable that is a field of a class, you can specify classvariable.fieldname.
  • If you try to evaluate a variable before it has been initialized, one of two things can happen. Either a Variable not available to display message is shown, or the uninitialized contents of the variable are shown, which could be a strange value.