CSC300: Python to Java: Trace basics [36/40] Previous pageContentsNext page

The stdlib package contains a class Trace which can be used to visualize the execution of programs.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
package algs11;
import stdlib.*;
public class Hello {
  public static void main (String[] args) {
    //Trace.showBuiltInObjects (true);
    //Trace.showBuiltInObjectsVerbose (true);
    Trace.drawSteps ();
    Trace.run ();
    int i = 0;
    while (i < 3) {
      StdOut.print ("Hello");
      i = i + 1;
    }
  }
}

Trace.run() causes the program to be run in a debugger.

Trace.drawSteps() causes a drawing to be created at every step of the contains method. The drawings will be created in a folder on your Desktop. To change the location, or for further discussion, see here.

Try running this program.

Try it with int replaced by Integer.

Try it uncommenting Trace.showBuiltInObjects.

Try it uncommenting Trace.showBuiltInObjectsVerbose.

Previous pageContentsNext page