Top 10 Java Debugging Tips with Eclipse

In this tutorial we will see about debugging java applications using Eclipse. Debugging helps us to identify and fix defects in the application. We will focus on run-time issues and not compile time errors. There are command line debuggers like gdb available. In this tutorial we will focus on GUI based debugger and we take our favourite IDE Eclipse to run through the tutorial. Though we say Eclipse, the points are mostly generic and is suitable for debugging using most of the IDEs like NetBeans too.

Before going through this tutorial, I recommend you to have a look at Eclipse shortcuts and it will really help. My Eclipse version is Juno as of writing this tutorial.

  • Do not use System.out.println as a tool to debug.
  • Enable detailed log level of all the components involved.
  • Use a log analyzer to read logs.

1. Conditional Breakpoint

Hope we know how to add a breakpoint. If not, just click on the left pane (just before the line number) and a breakpoint will be created. In debug perspective, ‘Breakpoints’ view will list the breakpoint created. We can add a boolean condition to it. That is, the breakpoint will be activated and execution will hold only if the boolean condition is met otherwise this breakpoint will be skipped.

2. Exception Breakpoint

In Breakpoints view there is a button labeled as J! We can use that button to add a java exception based breakpoint. For example we want the program to halt and allow to debug when a NullPointerException is thrown we can add a breakpoint using this.

3. Watch Point

This is one nice feature I love. When a chosen attribute is accessed or modified program execution will halt and allow to debug. Select a class variable in Outline view and from its context menu select Toggle Watchpoint. This will create a watch point for that attribute and it will be listed in Breakpoints view.

Ads by Google

4. Evaluation (Display or Inspect or Watch)

Ctrl+Shift+d or Ctrl+Shift+i on a selected variable or expression will show the value. We can also add a permanent watch on an expression/variable which will be shown in Expressions view when debug is on.

5. Change Variable Values

We can change the value of a variable on the fly during debug. Choose a variable and go to Variables view and select the value, type and enter.

6. Stop in Main

In Run/Debug Settings, Edit Configuration we can enable a check box that says Stop in main. If enabled when we debug a java program that launches with a main method, the execution halts at first line of main method.

7. Environment Variables

Instead of going to System properties to add an environment variable, we can conveniently add it through Edit Configuration dialog box.

8. Drop to Frame

This is the second best feature I love. We can just return the control to any frame in the call stack during debug. Changes made to variables will not be reset. Choose the stack level which you want to go back and restart debug from there and click the drop to frame button from debug toolbar. Eclipse is cool!

9. Step Filter

When we Step Into (F5) a method we may go into external libraries (like java) and we may not need it. We can add a filter in preferences and exclude packages.

10. Step Into, Over and Return

I kept this as the last point as this is the first thing to learn in debugging :-)

  • F5 – Step Into: moves to next step and if the current line has a method call the control will go into the first line of the called method.
  • F6 – Step Over: moves the control to next line. If there is a method call in the current line, it executes the method call internally and just moves the control to next line.
  • F7 – Step Return: When done from inside a method the control will move to the calling line from where the current method is invoked.
  • F8 – Move to next breakpoint.

This Core Java tutorial was added on 30/08/2012.



Comments on "Top 10 Java Debugging Tips with Eclipse"

  1. George says:

    This is great. Thanks.

  2. ramesh says:

    Nice way of explanations

  3. Jun says:


  4. Ganesh says:

    Hi guys,

    I Debug a one program successfully.
    After that when i am doing debugging another program the error message has been displayed like source not found…

    please help me

  5. santosh says:

    good sir your tutarials

  6. Edward says:


    Could you tell me how to add multi Conditional Breakpoint. I tried to do something like: nName.equals(“A”) && mAge == 12
    But it didn’t work.

  7. reshma says:


  8. Sachin says:

    Very concise and well written. Thanks.

  9. kushi says:

    Thanks for sharing ur knowledge.. Appreciated!!

  10. yuvraj thorat says:

    Very nice explaination, keep writing….Hurray!!!!!!!!

  11. Nilesh says:

    Hi ,
    Nice artical. Joe actuallu i am working on one tool where i can’t use eclipse or any advanced tool for debugging. Only solution is we can debug by entering System.out.println() in a code. actuallly i want to know that is there any tool which add this System.out.println automatically in java file for every posiible variables . Waiting for your replay. Thank you in advance.

  12. Venkatesh says:

    Thanks Joe!

  13. […] you will blame me, saying you didn’t expect a so basic article from me. If you are looking for Eclipse debugging tips in general, you can refer to this earlier written super hit […]

  14. pinky says:

    joe sir..
    awesome job… very useful

  15. Anonymous says:

    Great, I ve learned new useful features

  16. Anonymous says:

    Great, I ve learned new useful features (4+5+9)

  17. Anonymous says:

    This is Great!

    display is also a great debugging tool in eclipse that you should talk about.

  18. Anonymous says:

    well documented

  19. venkat says:

    well concepts. really thanks …….

  20. It’s very good tutorial,very useful….
    thanx Joe..

  21. Suriya says:

    Thanks for explaining it in very simple and effective way

  22. Amateur says:

    Woah! I’m really loving the template/theme of this website. It’s simple, yet effective.
    A lot of times it’s hard to get that “perfect balance” between user friendliness and visual appearance. I must say that you’ve done
    a very good job with this. Additionally, the blog loads extremely quick for me on Chrome.
    Excellent Blog!

  23. Mohammed Subhi says:

    when I use Expression to variable inside object I face the error (error during the evaluation)

  24. Kyle C says:

    awesome Thanks

  25. sivaram says:

    great tutorial. very useful

    thanks alot

  26. Jay says:

    Good Website….
    could you help me…..
    how to edit falsh template…..
    please help me out…..

  27. silambarasan says:

    Very nice blog

  28. I Muyeed says:

    Look of ur website/blog is very attractive, I wish all the success. I got lot of in depth information from this about java.Thanks, I wish u all the success.

  29. pavan says:

    nice and useful article

  30. SaratthM says:

    Thanks Joe; Very useful!

  31. kirti says:

    very useful thanks!

  32. Babu says:

    Which is the ‘first best feature’ you love?

  33. jupiter says:

    Congrats for the article.

    One question. You say “Use a log analyzer to read logs”. Could you please give an example of such a log analyser?
    I use basic Unix commands to go through the logs. I would be interested in taking a look at such a log analyser. What would the key features be?


  34. Amol patil says:

    Thank you very much
    Very good Info..
    may god bless you with whatever you want.. :)

  35. Pitabasa Biswal says:

    Thanks a lot sir

  36. Anonymous says:

    thank you sir loved article alot

  37. Anonymous says:

    Hi Joe,
    your site is too good to read and it is very useful article for java guys.

    kiran G.

  38. Sikandar says:

    good info!!

  39. jegan says:

    you are super in explaining.. really very good articles all of them ..

  40. Anonymous says:

    You are doing an awesome job here!!… I think your site is one of the best ones to deliver a clear knowledge of Java which is really helpful!!!.. Keep up the good work

  41. Joe says:


    if you can share the exact error trace, I can attempt to solve it.

    Recently with Juno I face some similar error message. It was the first time when I was setting up Juno. Then I doubted about the downloaded zip file and I removed the whole setup, downloaded it fresh again and it worked nicely.

    My guess is some files may be missing or corrupted.

  42. Padmanaban says:

    Hi Joe,
    I was trying to launch Eclipse Juno in my laptop which is installed with jdk1.7.0_01 with update 7. But Eclipse is getting terminated every time with the error message that failed to load JNI Shared library from the source. I dont understand that message and I have checked my PATH and CLASSPATH env variables and are fine. More over I am running my Netbeans IDE it is not complaining with the same error and also I am able to run java programme from the command prompt. This problem is only with eclipse. please guide me to settle this problem


  43. Anonymous says:

    Great collection

  44. Anonymous says:

    very useful information at one place for software developers ..

  45. J...?...V...? says:

    Nice one, i liked it so much…..keep writing…

  46. SR says:

    Thank You Joe. Very useful, concise and to the point.

  47. dayang says:


  48. Deepak says:

    Brilliant! Thanks a lot…

  49. abs says:

    thanks! Just what I was looking for.

  50. Anonymous says:

    great work .. thanks for the much needed help in eclipse debugging

  51. S L N V Praveen says:

    superb Joe…

  52. jcaleb says:

    thanks man…. i dont know 8 out of 10 you posts. must catch up on my eclipse skills

  53. Anonymous says:

    Useful tips.
    Have you ever tried debugging xqueries in eclipse?
    Please write something if you know something related.

  54. Mayur Kumar says:

    Hi Joe,

    Thanks for your valuable input on the Eclipse IDE.
    It is really good.

    keep the good work.

  55. Kent says:

    nice article

  56. ram says:

    Really good one…

  57. Ram says:

    Really cool tips….

  58. Murali says:

    very interesting post. As a developer should know these techniques of debugging.

  59. Anonymous says:

    serious gud one

  60. V Kishore Marisetty says:

    really use full, and simple

    Thank you very much…

  61. Anonymous says:

    Really Helpful…Thanks

  62. Anonymous says:

    Getting more information. Please keep post such information. Thanks

  63. mohan says:

    Nice post and Well Explained.Thank You

  64. java67 says:

    Great information, thank you

  65. SANKAR says:

    Very use full information send me more information

    thank u
    Sankar svs

  66. Hardik says:

    Awesome , Whenever I read your articles I really learn new thing, great…

  67. Anonymous says:

    Very useful information.. Nice keep send more information’s

    Anandan R

  68. Satish says:

    Nice Job. Keep going

  69. Prashant says:

    Thanks JoeSir,

    it,s very useful and easy to understand like it

  70. Gootam says:

    Good work Joe.. Please keep it up.

  71. G.Palanikumar says:

    Respected Sir,

    First I Thank you so much sir your website very useful to me.
    I am asking my doubts but i don’t know how to tell to you. Q1)How to input more than value at a time?. please give me example.

  72. Anonymous says:

    thanks joe…very well written.. your passion helps us..

  73. krishnamurthy says:


  74. Anonymous says:

    You are simply Superb

  75. amit h says:

    Very well written

  76. padmanaban says:

    could u explain clearly about API and Package

  77. Nagesh Kekan says:


  78. chetan says:

    Very useful , every developer should know these things.

  79. says:

    Thanks Joe…

  80. saidulu says:

    This is what looking what long time, it’s really very good tutorial..

    Please explain servlet and jsp’s debbuging using live example as above.

  81. askkuber says:

    thanks you for detail inforamation in one place

  82. IDEA user says:

    Nice one.
    Can you write a IDEA version?

  83. sandeep says:

    Sir, keep writing such wonderfull tutorials.

  84. srinivas says:


  85. Kapil says:

    Very useful Indeed!
    Thank you very much.

    • S says:

      Sir, i want you to post on remote debugging with eclipse, have been trying hard to find simple way of doing.Hope,you can really explain in better way.

    • Shailaja says:

      Sir, i want you to post on remote debugging with eclipse, have been trying hard to find simple way of doing.Hope,you can really explain in better way.

Your Comment