10 Tips for debugging Java in eclipse

Source: Internet
Author: User

Before reading this article, I recommend that you take a look at the Eclipse Accelerator Manual, my version of Eclipse is 4.2 Juno.

Three points first.

    • Do not use SYSTEM.OUT.PRINTLN as a debugging tool
    • Enable verbose logging levels for all components
    • Use a Log Parser to read the log

1. Conditional breakpoint

Imagine how we usually add breakpoints, and it's common practice to double-click the left side of the line number. In the debug view, breakpoint View lists all breakpoints, but we can add a Boolean condition to determine whether the breakpoint is skipped. If the condition is true, the program stops at the breakpoint, otherwise the breakpoint is skipped and the program resumes execution.

2. Abnormal Breakpoint

There is one in the breakpoint view that looks like J! button, we can use it to add a breakpoint based on an exception, for example we want the program to pause when NullPointerException throws, we can do this:

3, Observation point

This feature I like very much, he allows the program execution to pause and debug when a selected property is accessed or changed. The simplest way is to double-click the line number of the statement that declares the member variable in the class, and you can add an observer point.

4. View variables

You can see the value of the variable using CTRL+SHIFT+D or Ctrl+shift+i on the selected variable, and we can also add monitoring in expressions view.

5. Change the value of the variable

We can change the value of the variable at debug time. You can do this as shown in variables view.

6. Stop in the Main methodIn the Run/debug setting, we can enable this feature as shown. The program will stop at the first line of the Main method 7. Environment VariablesWe can easily add environment variables in the Edit Conriguration dialog box 8. Drop to FrameThis feature is very cool and is my second favorite feature, Drop to frame means that it can be re-executed at the beginning of the current method, and the values of all the context variables are back to that time. Not necessarily the current method, you can click on any frame in the current call stack to jump there (except for the first frame). The main use is that all variable states are quickly restored to the beginning of the method and re-executed again, so that you can debug it over and over again in the context of your concern (combined with other functions such as changing the value of the variable), instead of having to debug it again. Of course, the side effects of the original execution process are irreversible (for example, you inserted a record into the database). 9. Step FiltrationWhen we debug the F5 will go into the inside of the method, but there is a drawback sometimes may go into some libraries inside (such as the JDK), may not be what we want, we can add a filter in the preferences, exclude the specified package.

10. Enter, Skip, return

In fact, this technique is the most basic knowledge of Debug.
    • F5-step into: Move to the next step, if the current line is a method call, will enter the first line of this method. (Can be excluded by the Nineth article)
    • F6-step over: Moves to the next line. If the current row has a method call, the method is executed and returned to the next line.
    • F7-step Return: Resumes execution of the current method, and when the current method finishes executing, the control will go to the row that the current method is called.
    • F8-moves to the next breakpoint.

10 Tips for debugging Java in 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.