How To Set Conditional Debug Breakpoints in Eclipse or IBM RAD?

Developers and Production Support Analysts will, in their lifetime, spend a lot of time debugging, specially if the applicaiton is complex and they have no idea on what’s going on. I mentioned Production Support Analysts because they are the ones in most companies analyzing and fixing the defects in production environments. Developing the new features probably does not need you as much to debug as it needs for maintenance work, specially if you are trying to understand what’s going on and what is the flow.

There are many occasions you don’t want to debug every steps. For example, if there is a for loop that loops for a 1000 times and that you know it fails on the 100th step or are intersted to see what’s going on somewhere around that, would it make sense to go through the 99 steps of debugging before hitting the 100th one? It certainly does not make sense to me unless you have a lot of time to hit those debug short cuts (I love those F5,F6,F7,F8 shortcut keys in Eclipse and IBM RAD by the way).

So what can you do about it? Well the IDEs like Eclipse or IBM RAD offer you a way to set conditional breakpoints – the IDE will stop at the breakpoint you set only when certain conditons are met.

The following is some piece of code with a for-loop. Let’s say we are interested to look at the value of the variable ‘random’ when the value of i is 100.

 * @author Kushal Paudyal
 * Written to be used in a tutorial to show how to do 
 * conditional break points in eclipse

public class ConditionalBreakPointEclipse {

    public static void main(String args[]) {


    /** Just outputting some random numbers. We would like to
     * add a conditional breakpoint when the value of i is 100.
    public static void doSomeStuff() {

        for (int i = 0; i <= 1000; i++) {

            double random = i * Math.random();

            System.out.println(i + " - Random - " + random);


The first step is to set a breakpoint where it says

double random = i * Math.random();

Here is a screenshot for that.

Eclipse - Putting a breakpoint

The second step is to right click on the breakpoint and choose ‘Breakpoint Properties…’.

Eclipse - right click on the breakpoint

On the third step, enable the checkbox ‘Conditional’. The text area underneath the checkbox will be enabled and that is a place where you can put your conditions. In my case, I simply typed in i==100 because I wanted to stop when the value of i is 100.

Eclipse - Adding the conditional in the Line Breakpoint Properties

Now close the window and run the application in debug mode. You will see that after the value of i reaches 100 and when the statement where we put the breakpoint is reached, the IDE will stop for you to evaluate the variables at that point. Isn’t that neat? Once you hit F7, the program should continue without another stop at the breakpoint.

Eclipse - Debugging with conditional breakpoint

Compare this to not having a conditional breakpoint. You would have to step through 99 times before it reached your desired value of i and to finish debugging the program, you would have to hit F7 for another 900 times (or just stop debugging)!!

You are going to appreciate that IDEs provide this great feature.