Here are the steps to do extensive debugging of java code using Eclipse IDE with watch variables, expression and Inspect.

Step1: Enable breakpoint

Set the breakpoint at the line of code or point of method entry from where you would like to start debugging the code. Right click on the left margin of the editor next to the line of code and a context menu pops up. Select toggle breakpoint in the context menu as shown below:

Figure1: Toggle Breakpoint



Step2: Configure the breakpoint to stop execution

To start debugging, the execution should stop at the breakpoint specified. For this click on breakpoint properties (refer Figure1)  and do the following:

  1. Check Hit count
  2. Specify value as 1
  3. Select “Suspend thread” option

This will stop the execution when the program hits the breakpoint.



Step3: Switch to debug perspective

In Eclipse, select Window –>Open Perspective –> Debug as shown below:

Step4 switch to debug perspective


Step4: Run in debug mode

Now run the program in debug mode. Select Run –> Debug

Step5 Run in debug mode

Now the program starts running in debug mode and you would see the state of the thread as “running”

Step6 running thread

When the program hits the breakpoint the state of the thread changes from “running” to “suspended

Step7 suspend thread


Step5: Debugging the code with Expressions \Watch variables \ Inspect

Now the code stops at the breakpoint. You could use the watch variables / expression to monitor the current value of the debug variable.

Suppose you set the breakpoint at the variable named “counter” and the program stopped at counter variable as shown below:

step8 stops at code\

Add the expression with the variable name “counter” which allows you to monitor the value of the variable as you execute the program:

Step11 watch variableexpressions

You could also right click on the counter variable and select “Inspect” from the context menu

Step12 right click to inspectstepinto

If it is a method then, select the method name and click on “Step Into Selection“. This will allow you to monitor or debug the method execution line by line.


Step6: Use F6 key to step into the method

To “step into” the next executable line of code in the current method, press the “F6 Key”. This will pass the program control from the current line to the next executable line of code.

Step9 Press F6 key


Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks