Again! – 10 Tips on Java Debugging with Eclipse


You probably know some post of this kind. “n things about debugging” is a popular topic. For a good reason! I guess that I spent about 1 hour per day debugging my applications. That’s quite a lot time. This makes it even more important to know all the handy features, that makes your life easier and helps you to safe some time. And it justifies another post on this topic!

– First Tip: Don’t debug too much!

Crazy statement to start a post about debugging. 😉 But it must be said! Try to split up your complex logic into many isolated units and write Unit-Tests to check the correct behaviour of your code. I see it very often, that people are clicking through large web-applications, filling out multiple forms, switching to different pages in the flow, just to check a calculation logic on the last page and after that implementing big parts of the logic in the debug view. Before starting your tomcat always ask yourself: Is there a way to check the behaviour with a unit test? But you can find tons of good material about good code design out there, from here I will focus on a few eclipse debugging tips, which you maybe don’t know or you have forgotten over the time.

– Breakpoint View : Conditional Breakpoints

Extreme useful if you are interested only in a special constellation of your application. For example if you want to see the 13th run in a loop or you are debugging functionality in an abstract super class and you only want to see one concrete implementation. You can setup the conditions in the breakpoint-view or with the contextmenu on the blue breakpoint-marker next to your code (“Breakpoint Properties”). You can choose to suspend when your code-snippet gets true or when the value of your snippet changes.
Conditional Breakpoints
Conditional Breakpoints II

– Variables View: Show Logical Structure

If you want to see the values of a Map or a List in the variables view, it’s not always that easy with the default setting of eclipse. If you are using a HashMap for example, you have to click through the physical entries and you are confronted with implementation details of a HashMap. But there is a small button above the variables – “Show Logical Structure”. Very handy, especially if you don’t have meaningful toString()-methods for the objects in your structure. My boss showed me this feature a few weeks ago. You know, he is the guy who is working with PowerPoint or Excel the most time. What a shame for a developer like me 😉

Without “Show Logical Structure”

Logical Structure I
With “Show Logical Structure”

Logical Structure II

– Variables View: Change Value…

Instead of restarting your debug session with some slightly changed input data, let’s say entered in a web-form – you can also change the values of your variables directly during debugging. Sometimes you can safe some time and sometimes you can simulate some strange behaviour with that feature a bit easier.
Change Value

– Display View

Do you know the “Display View”? You can activate it during debugging via “Window” -> “Show View” -> “Display”. Now there should be a blank new view in your Eclipse. You can use this view to enter and evaluate new code. The code is executed within the context of the current debugging positions, which means that you can use all your variables and even content assist. To execute your code, just mark it and use the context-menu or CTRL+U (execute) or CTRL+SHIFT+I (inspect).
Display View

– Navigation: Drop to Frame

I think everybody knows “Step Into”, “Step over” and maybe “Step return”. That are the basics to navigate through your code while you are debugging. I want to name 2 further ways to navigate, which I like very much. The first is “Drop to Frame”. With that feature you have the possibility to go back in time 😉 You can simply go to a point in your java stackframe where you have been before. It happens to me quite often, that I am debugging and then missing the point where I have to pay attention. With the “Drop to Frame”-Feature I can then run the code again very simple.
Drop to Frame

– Navigation: Step into Selection

The second one is “Step into Selection”. This is a pretty easy one, but not many people are using it. For that, you just have to press Ctrl+Alt and click on a method name, where you want to go. Very handy, very fast. Compared to the usual “Step Into” this is much better for example if you want to enter a method with many parameters and you one step trough all the parameter evaluations. “Run to line” is also a nice feature. Just place your cursor in front of the line where you want to stop and hit “CTRL+R”.
Step Into Selection

– Navigation: Use your keyboard

You are faster, if you avoid to use the mouse. You should know at least the following Shortcuts:

  • F5 – “Step Into”
  • F6 – “Step Over”
  • F7 – “Step Return”
  • F8 – “Resume”
  • Ctrl+Shift+B – “Toggle Breakpoint”
  • Ctrl+Shift+I – “Inspect”


– Breakpoint View: Watchpoints

What the hell is changing this variable?! Sometimes it is usefull to create a watchpoint. Then the debugger stops, whenever the watched field is changed or just read – you can configure that. Just doubleclick on a field, then you can see the watchpoint in the Breakpoint View and edit the properties. You can even configure a hit count, means that the debugger only stops, when the entered hit count is reached. This also works for usual breakpoints.
Watch Point

– Human Readable Objects

The Variables View is using the toString-Method of your objects to display the value. Because of this it is very, very helpful
to provide good toString-implementations. The javadoc of the default-toString-implementation in java.lang.Object recommends the same:

* Returns a string representation of the object. In general, the
* <code>toString</code> method returns a string that
* "textually represents" this object. The result should
* be a concise but informative representation that is easy for a
* person to read.
* It is recommended that all subclasses override this method.

You can have a look at the ToStringBuilder in commons-lang. It provides some functionality to write – quote from the javadoc – “good and consistent” toString-methods.


Example from ToStringBuilder – Default

Example from ToStringBuilder – Multiline-Style

If you cannot modify the toString-implementation, for example if you are working with frameworks or you have to use a foreign API, it might be an option to create an “Detail Formatter” in Eclipse. To do that, you have to right click an object in the variables view and click on “New Detail Formatter…”. Then you can provide some code to display this type of Object in the future.
Detail Formatter


  • April 9, 2013 von Juha Vainikka

    brilliant post

  • Amazing post! I cannot thank you enough for it, as I spend far more than one hour per day on the debugger, sadly. I wasn’t aware of this functionality, and i can quickly see how much more efficient i will be.

    Thank you 🙂

  • I am happy to be able to say I knew most of the tricks here (but perhaps that’s because I spend too much time debugging? But with legacy code, you have now much choice…)
    But I didn’t know the Step into Selection and Drop to Frame features.
    The latter is automatic when you change code in the method you edit, but it is useful to be able to do it on demand.
    The former is what I wished for long without knowing it was available! It is so much easier than navigating to the method we want to enter and to Ctrl+R (run to line) to the start of this method!
    A big thank you for this compilation!

  • Thanks a lot. I am totally new to debugging and I am sure that, these tips will be very helpful!

  • May 16, 2014 von Badal

    Excellent blog!!!

    Thanks for sharing. This makes the debugging very easy…

  • August 5, 2014 von madi

    Hi there,
    I can not see the variables values from where you mentioned, I can see that box bot it’s whole blank. I do not know why?!

  • I spend a lot of time in the Eclipse debugger, too. It has a lot of tools that let you control where to step, but it doesn’t do a great job of showing you the data.

    The Mirur Eclipse plugin lets you visualize your data as you debug quickly and intuitively. Once you click on an array or list of numbers, it immediately plots your data in OpenGL so you can interact with it.

  • October 22, 2014 von Binh Thanh Nguyen

    Thanks, nice post

  • December 8, 2014 von Madpro

    Awesome post excellent ,loved it keep’em coming this is in my bookmarks now, thanks once again

  • Thank you very much .These tips will be very helpful!


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