Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
9Activity
0 of .
Results for:
No results containing your search query
P. 1
Debugger & Profiler in NetBeans

Debugger & Profiler in NetBeans

Ratings: (0)|Views: 162|Likes:
Published by huubang
Hands-on demo about using debugger and profiler in NetBeans IDE
Hands-on demo about using debugger and profiler in NetBeans IDE

More info:

Published by: huubang on Apr 11, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

11/19/2011

pdf

text

original

 
 
D
EBUGGER
&
 
P
ROFILER IN
N
ET
B
EANS
6.0H
ANDS
-
ON
D
EMO
 
Using the debugger:
Debugging is the process of examining your application for (runtime) errors. The process of debugging is accomplished by setting breakpoints and watches in your code and running it in thedebugger. This enables you to execute your code line by line and have a closer look at the state of your application (values of variables, call order, etc.) in order to discover any problems.
S
TEP
1
: Write a simple application
 
Create a new Java Application
 
Under the
main
method, write the following code:
 
Under the
Main
class, add the following methods:
private static int square(int x) {return x*x;}private static int add(int a, int b) {return a+b;}int sum = 0;for (int i=0; i<100000; i++) {sum = add(sum, square(i));}System.out.println("Sum is " + sum);
 
 
S
TEP
2
: Set a breakpoint at the
main
method
 
A breakpoint is a flag in the source code that tells the debugger where to stop execution of theprogram. When your program stops on a breakpoint, you can perform actions like examining thevalue of variables and single-stepping through your program.To set a breakpoint, Click in the left margin next to the line in the source code or put the insertionpoint in the line and press Ctrl-F8.
S
TEP
3
: Run the debugger by pressing Ctrl-F5
S
TEP
4
: Step through your programOnce execution of your program is halted, you can step through your lines of code using thefollowing commands on the Debug menu or toolbar:
 
Step Over (F8).
Executes one source line. If the source line contains a call, executes theentire routine without stepping through the individual instructions.
 
Step Over Expression (Shift-F8).
Executes one method call in an expression. If an expressionhas multiple method calls, you can use Step Over Expression to step through an expressionand view the value of each method call in the expression in the Local Variables window. Eachtime you use the Step Over Expression command, the debugger advances to the nextmethod call in the expression and the completed method call is underlined. Step OverExpression behaves like Step Over when there are no additional method calls.
 
Step Into (F7).
Executes one source line. If the source line contains a call, the IDE stops justbefore executing the first statement of the routine. You can also start a debugging sessionwith the Step Into command. Program execution stops on the first line after the
main
routinebefore any changes have been made to the state of the program.
 
Step Out (Ctrl-F7).
Executes one source line. If the source line is part of a routine, executesthe remaining lines of the routine and returns control to the caller of the routine. Thecompleted method call is highlighted in the Source Editor.
 
 
S
TEP
5
: View program informationTo view variables and expressions, either:
 
Use the local variables window
 
Or move your mouse over the variable
 
Or create a watch
o
 
Select the variable or expression in the Source Editor, right-click, and choose NewWatch (Ctrl-Shift-F7).
The New Watch dialog box opens with the variable or expression entered in the text  field.
o
 
Click OK.
The Watches window opens with the new watch selected.
E
XTRA
T
ASK
: Use the call stackThe Call Stack window lists the sequence of calls made during the execution of the current thread.By default, the Call Stack window opens automatically whenever you start a debugging session. Toview the call stack (in case you don’t see it), choose menu Window – Debugging – Call Stack or pressAlt + Shift + 3

Activity (9)

You've already reviewed this. Edit your review.
1 hundred reads
ALi liked this
ALi liked this
ALi liked this
nobalm liked this
cn2_k5a3760 liked this
bitbucket88 liked this
arisan_602000 liked this
Emile Anatoh liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->