10 Tips for debugging Java with Eclipse __java

Source: Internet
Author: User

Do not use SYSTEM.OUT.PRINTLN as a debugging tool

Enable verbose logging levels for all components

Use a log analyzer to read logs

1. Conditional breakpoint

Think
Like how we normally add breakpoints, the usual practice is to double-click the left side of the line number. In the debug view, breakpoint View lists all breakpoints, but we can add a
A Boolean-type condition to determine whether the breakpoint has been skipped. If the condition is true, the program stops at the breakpoint, otherwise the breakpoint is skipped and the program continues to execute.

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 the exception, for example we want the program to pause when the NullPointerException is thrown:

3, Observation points

This feature I like very much, and he allows the program to pause and debug when a selected attribute is accessed or changed. The easiest way to do this is to add an observation point by double-clicking the line number on the left of the statement that declares the member variable in the class.

4. View variable

Use Ctrl+shift+d or Ctrl+shift+i on the selected variable to view the value of the variable, and we can also add monitoring in expressions view.

5, change the value of the variable

We can change the values of the variables in the debug time. You can do this in variables view as shown in the following illustration.

6. Stop in Main method

In the Run/debug setting, we can enable this feature as shown in the following figure. The program will stop at the first line of the Main method

7. Environment variable

We can easily add environment variables to the Edit Conriguration dialog box

8. Drop to Frame

This
Feature is very cool, is my second favorite feature, Drop to frame that is, you can jump back to the beginning of the current method to rerun, and all the values of the context variables are also returned to the
When 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 purpose is to quickly restore all variable states to the start of the method
The way you do it again, you can debug it over and over again in the context that you are concerned with (by changing the value of variables, and so on), without having to go through the debugging again. Of course, it turns out
The side effects that occur during execution are irreversible (for example, you insert a record into the database).

9. Step Filtration

When we are debugging, press F5 will go inside the method, but there is a drawback sometimes may go into some of the library inside (such as 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: Moves to the next step, and if the current row is a method call, it will enter the first row of the method. (Can be excluded by the Nineth article)

F6-step over: Move to the next line. If the current row has a method call, the method is executed and returned, then to the next line.

F7-step return: Continues execution of the current method, and when the current method finishes execution, control goes to the line that the current method is called.

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.