How to do Debugging in Eclipse?

Posted by Shanky Sohar  •  April 18, 2011

Many developer don't realize how much getting rid of software bugs can cost.If you are a developer,then you must be a good debuggers also. There was a time when a typical developer used a very old fashioned technique of debugging that is using a system.out.println( ) method .Code traces were printed to the console, a file or a socket. It is a rare developer who creates a prefectly fine code in the first time. Debugging allows you to walk through code,look at the output,and inspect variables. Remember 80% of the time is required while maintaining the code while 20% of the time is required while developing it.So,make sure that your code is error free.

Lets us create a Java Project "TechieSafari".With the two classes as

  • Main.Java..This class will contain Main() Method.
  • Count.java..This class will contain a counter which will do some calculation.
Main.java will look like this. Count.java will look like this.
Now in order to do the debugging, First you need to set debug point i.e Break point.

How to set Break point

Breakpoint is an intentional stopping or pausing place in a program, put in place for debugging purpose. To set the breakpoint, Right click on left column or you can double click on that place.


This is how breakpoint looks like
Now we have to start the debugger.Right click on the class which contain main method say Debug as Java Application. If your class doesn't have any debug point then Program will run as normal. Remember it is necessary to have some Breakpoints in your class code to make sure your class run in a debugging mode. When you say Debug as Java Application. You will get a warning message about changing the perspective.Just say "yes" and then you will be automatically switch to Debug perspective.Which looks like below
Now if you want to explore the coding there is few keys which will help you explore through a complete code which are as F5 / F6, F7 and F8.
  • F5 ..This Key will help you to reach next step in a program,This may be method/function or class anything.
  • F6..This Key will help you to step over a method/Function of a class.
  • F7..This Key will help you to return to a step backward.
  • F8..This Key will help you to reach a next breakpoint,If there is no breakpoint then the program will normally run.
These keys are only the shortcuts to use the features but if you like not to use the keyboard irrespective want to use User interface of eclipse then see below. So,this is the basic and most beautiful way of doing the debugging.

Subscribe to SCJP Material

Be the first one to post your comments