10 Eclipse debugging techniques that Java programmers should know

Source: Internet
Author: User

Debugging can help identify and resolve application flaws, in this article, the author will use the common development tools eclipse to debug Java applications. But the debugging methods described here are basically generic and apply to the NetBeans IDE, and we focus on the runtime.

Before we begin, we recommend that you take a look at the Eclipse shortcuts article, which will bring you a lot of convenience. The Eclipse Juno version (Eclipse 4.2) is used in this article to give you 3 suggestions before you start!

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

Activate and use all of the component log levels involved

Using Log Analyzer to read logs

 1. Conditional Breakpoint

If you don't know how to add a breakpoint, simply click on the left panel (front of the line number) to create the breakpoint. In the debug interface, the Breakpoints view lists all the breakpoints that were created. We can give it a Boolean condition, that is, the breakpoint will be activated and if the Boolean condition is true, the breakpoint will be executed, or it will skip down execution.

  2. Exception Breakpoint

In the breakpoint view, there is a j! tag button! We can use this button to add a Java exception breakpoint. For example, we want the program to continue debugging when it encounters a null pointer exception (nullpointerexception), so we can use that button to add an exception breakpoint!

 3. Surveillance points

This is a very good feature when a selected property accesses or modifies a program, and the program stops executing and allows debugging. Select a class variable in the outline view and select Toggle Watch from the context menu, and the property watch point is created, and all watch points are displayed in the form of a list in the breakpoint (breakpoints) view.

  4. Assessment/Inspection

Press Ctrl+shift+d or Ctrl+shift+i to display the value of the selected variable or expression. We can also add a permanent observation point to a variable or expression, which is displayed in the expression view when the program is debugged. Expression

 5. Modify the value of the variable

During debugging, we can modify the value of the variable. First select a variable and then enter the variable view (Variables view), according to the variable type in its corresponding value column input values.


  6. Stop execution inside the main function

In the Run/debug settings, the Edit Configuration dialog box has the "main" tab and we can check the "Stop in Main" checkbox. If selected, when you debug a Java program that is based on the main method, the program stops executing at the first line of the Main method.

  7. Environment Variables

Instead of adding environment variables to the system properties, we can easily add them in the Edit Configuration dialog box.

  8.Drop to Frame

This is one of my favorite features. During debugging, you can jump back to the beginning of the call stack frame and the value of the variable will return to the original. The depth of the stack is adjusted according to the back file, the main use of this feature is that all variable states can be quickly returned to the way the method starts to execute, and then you can do it over and over again, so that you can debug multiple times in your area of concern, but there are also some side effects during the execution. For example, the data inserted into the database can not be deleted!

 9. Distributed Filtration

When we enter the (F5) method, we can also access its external libraries (such as java.*), we may not need this library, we can add a filter on the Perference tab page to exclude this package.

  10. Enter, jump and return

I put this on the last point, in the debugging process, these are the things that must be understood (best mastered):

f5--Enter: Move to the next step, if there is a method call to the current line, the control jumps to the first line of the invoked method.

f6--Jump: Move to the next line. If there is a method call on the current line, it is moved directly to the next line of execution. Does not enter the called method body.

f7--return: Jump out of the current method and proceed down.

f8--moves to the next breakpoint to execute.

Reprint: http://tech.it168.com/a2012/1024/1412/000001412535_all.shtml

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.