1 / 13

DrJava Debugger by Dr. lee 10/2008

DrJava Debugger by Dr. lee 10/2008. Tracing Execution. One way to trace what is happening in your program is To add System.out.println() statements Add these to print out the value of the current object’s name before and after the name is initialized in the constructor that takes a name

odina
Download Presentation

DrJava Debugger by Dr. lee 10/2008

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DrJava Debuggerby Dr. lee10/2008

  2. Tracing Execution • One way to trace what is happening in your program is • To add System.out.println() statements • Add these to print out the value of the current object’s name before and after the name is initialized in the constructor that takes a name • System.out.println(sum); • sum = sum + myScore; • System.out.println(sum);

  3. Sample Program 1 public class Sample1 { public static void main(String[] args) { int sum = 0; int myScore = 100; System.out.println(sum); sum = sum + myScore; System.out.println(sum); } }

  4. Debuggers • You can use a debugger to find the cause of bugs (errors in your program) • A moth caused one bug • http://www.jamesshuggins.com/h/tek1/first_computer_bug.htm • And to trace execution to see what is happening • Which constructor is executed or what method is executed • What values are in the fields

  5. Open a File in DrJava • Open DrJava • Open the file “TestCircle1.java” in the directory “C:\CS202-DrJava\CS202-Liang-Textbook-Programs”

  6. DrJava’s Debugger • Click on Debugger in the menu • Then check the Debug Mode checkbox Stack and Threads Area Watches and Breakpoints Area Check values here

  7. Setting a Breakpoint • When you use a debugger you often want to set places to stop execution • Each place to stop at is a breakpoint • Once execution has stopped there • You can check the value of parameters and fields • To set a breakpoint • Right click on a line of code, then click “Toggle Breakpoint” • Or click the “Debugger” icon, then click “Toggle Breakpoint on Current Line” • It will be highlighted in red

  8. Showing a Breakpoint • Lines with breakpoints are highlighted in red in DrJava

  9. Testing a Breakpoint • Type the following in the interactions pane > java TestCircle1 • Execution should stop at the breakpoint and the color change to blue

  10. Show myCircle.radius value • Key in myCircle.radius in the Interactions Pane • You will see “Undefined class ‘myCircle’ “, why? • Execution stops before the breakpoint line is executed • So the class hasn’t been defined yet

  11. Check myCircle.radius Again • Click “Step Over” button, then key in myCircle.radius in the Interactions Pane again. • What do you see? Why? The current line of code has been executed

  12. Debugging Options • Step Over • Execute the current line of code and then stop again before you execute the next line of code • Step Into • If the line of code that we are stopped at has a method call in it, then stop at the first line in the called method • Step Out • Execute the rest of the current method and stop at the first line after the call to this method • Resume • Continue execution at the current point • Until the next breakpoint • Or the program ends • You can quit debugging by clicking on the X

  13. Ctrl-F to Show “Find” & “Replace” Windows Georgia Institute of Technology

More Related