10 Common tips for debugging Java with Eclipse

Source: Internet
Author: User

http://www.open-open.com/news/view/1ad9099

Read Catalogue

    • 1. Conditional Breakpoint
    • 2. Exception Breakpoint
    • 3. Watch Point
    • 4. Evaluation (Display or Inspect or Watch)
    • 5. Change Variable Values
    • 6. Stop in Main
    • 7. Environment Variables
    • 8. Drop to Frame
    • 9. Step Filter
    • Step into, over and Return

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 would be created. In debug perspective, ' breakpoints ' view would list the breakpoint created. We can add a Boolean condition to it. That is, the breakpoint would be activated and execution would hold only if the Boolean condition is met otherwise this Brea Kpoint'll be skipped.

Back to top of 2. Exception Breakpoint

In breakpoints view there is a button labeled as J! We can use this 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 u Sing this.

Back to top of 3. Watch Point

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

Back to top of 4. Evaluation (Display or Inspect or Watch)

Ctrl+shift+d or Ctrl+shift+i on a selected variable or expression would show the value. We can also add a permanent watch on an expression/variable which would be shown in Expressions view when Debug was on.

Back to top of 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.

Back to top of 6. Stop in Main

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

Back to top of 7. Environment Variables

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

Back to top of 8. Drop to Frame

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 won't be reset. Choose the stack level which your want to go back and restart debug from there and click the drop to frame button from Debu G toolbar. Eclipse is cool!

Back to top of 9. Step Filter

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

Back to top of 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 have a method call the control would go into the first line of th E 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 L Ine.
    • F7–step Return:when done from inside a method the control would move to the calling line from where the current method I s invoked.
    • F8–move to next breakpoint.

10 Common tips for debugging Java with Eclipse

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.