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.

[My Video Promotion]
  1. How to display UTF-8 characters in Eclipse / RAD Console
  2. Sample WSDL File Created By Apache Axix 1.3 From A Simple Java File
  3. Java Object Serialization and Deserialization In MySQL Database
  4. How To Set Conditional Debug Breakpoints in Eclipse or IBM RAD?
  5. Rotating An Image In Java Graphics 2D By Specified Degree
  6. Java Tip: How to extract the content of a Jar File Using Command Prompt
  7. How to change the author name in Eclipse Generated java comments?
  8. Java – How To Overlay One Image Over Another Using Graphics2D [Tutorial]
  9. How to use spaces in IBM RAD or Eclipse Instead of Tabs
  10. Quick SQL Reference – Find Duplicate Data In A Table Using Having Clause
  11. Splitting PDF File Using Java iText API Into Multiple PDFs
  12. Object Serialization And De-Serialization In Java To Filesystem
  13. Finding Java Image Pixels Information – ARGB (Alpha, Red, Green Blue)
  14. Creating A 3D Pie Chart In Java Using JFreeChart [Example Source Code]
  15. How to capture a screenshot using Java and save it to a file?
  16. Java Tutorial – Swing Text Drag And Drop – Sample Example
  17. Serialzing A Java Object Into XML and De-Serialzing using XMLEncoder And XMLDecoder
  18. Six Stages Of Debugging in Software Engineering
  19. Java 2D Graphics Example Tutorial On Paint, Gradient and Stroke
  20. Complete Tutorial On Using SOAP-UI to Mock Web Service Request / Response
  21. Listing The Content Of Zip File With Zip Information In Java
  22. How to delete saved SVN password from Eclipse IDE?
  23. Joke – Why do Java Programmers wear glasses?
  24. How to increase the number of recent workspaces in the eclipse based IBM RAD (Rational Application Developer) IDE?
  25. How to receive files via bluetooth in your MacBook Pro
  26. Calculating Folder Size Graphically and Generating Directory Size Chart In Java
Tagged , , , , , , , . Bookmark the permalink.

6 Responses to Calculating Folder Size Graphically and Generating Directory Size Chart In Java

  1. nocdib says:

    Thank you for this! It is just what I need

  2. d says:

    would that help you tocreate the file from ubunt server

  3. komal gaikwad says:

    in this code i got problem of array out of bound plz tell me solution.

  4. komal gaikwad says:

    In this code i got error
    Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 1
    plz send me proper code….

  5. Neethu says:

    Thank you very much for the solution. This is the one which i was searching.

  6. Manikant says:

    I need to copy to the shared folder which is shared and can be authenticate by using credentials.

    but here the code is giving to write .

    I need copy my folder from my local to shared location

    Please help

Leave a Reply to Manikant Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.