110 likes | 284 Views
Debugging. James Wei Professor Peck 1/24/ 2013 http :// goo.gl / kbbdmP. The E clipse Workbench. Perspective Task list Project Explorer view Outline Problems view. Debugging a P rogram. Debug perspective Select the file Make a breakpoint in your program
E N D
Debugging James Wei Professor Peck 1/24/2013 http://goo.gl/kbbdmP
The Eclipse Workbench • Perspective • Task list • Project Explorer view • Outline • Problems view
Debugging a Program • Debug perspective • Select the file • Make a breakpoint in your program • Double-click on the LHS • If you can’t see it, right click on the LHS ribbon and select Toggle Breakpoint • Click on the Debug icon.
Debugging a Program • Step Over • Step Into • Step Return • Resume • Terminate
Watching an Expression 1: publicclassMysteryClass { 2: 3:publicstaticvoid main(String args[]) 4: { 5:System.out.println(mysteryMethod(12)); 6: } 7: 8:publicstaticintmysteryMethod(int n) { 9: } }
Watching an Expression 8: publicstaticintmysteryMethod(int n) { 9: boolean array [] = newboolean[n]; 10: 11: for (int i = 0; i < n; i++) 12: { 13: array[i] = true; 14: } 15: 16: for (int i = 2; i < n; i++) 17: { 18: for(int j = 2*i; j<n; j=j+i) 19: array[j] = false; 20: } 21: 22: int count = 0; 23: for (int i = 2; i < n; i++) 24: if(array[i]) 25: count++; 26: 27: 28: return count; 29: } breakpoint
Watching an Expression • Go to Window Show View Expressions
Watching an Expression • Add array[i]to the Expressions view. • Addito the Expressions view.
Watching an Expression Step through: you can step over using Each time you step over, watch what happens to the values in the Expressions view in each iteration • What is the value of array[i] when i= 6? • What is the value of array[i] when i= 3? • What is the value of array[i] when i= 5? • What do you think this program is doing?
Enjoy the rest of your Friday! Don’t forget to submit your answers to get credit for today!