Elaborate MyEclipse commissioning

Source: Internet
Author: User

in case of problems with the program, we need to find and solve these annoying bugs in order to make the program run smoothly. However, when the code is a lot, the program is very large, it is very troublesome to find.

So, we need to use the debug (debug) method in the tool--eclipse/myeclipse. When debugging, we need the entrance and the observation point, so we need to set breakpoints to debug.

1 How to set breakpoints:

In the side bar of the line where you want to add a breakpoint, double-click/right-click Toggle Breakpoint.

2 Start Debug mode

After setting a breakpoint, right---debug As--java application in the project

or click here:

              

2 Where to set breakpoints:

A) attribute breakpoint: The breakpoint set on the row of the member variable

        (The flag on the side bar of line 4th)

b) Method Breakpoint: Breakpoint set at the execution or definition of the method (general recommendation is set at the execution point)

(17 line side bar logo)

c) Conditional breakpoint: Stops running the program after a certain condition is met

Set method: Right-click on the line where the breakpoint is located breakpoint properties (breakpoint property)--

            

Note:

1 when writing conditions for conditional breakpoints, do not have a semicolon. Sum > 8 (correct) sum>8; (error)

2 One principle to keep in mind when setting breakpoints: Which line sets the breakpoint, and which line will be executed when debugging.

So set the location correctly to avoid an uninitialized error.

For example:

& nbsp;                            public void print () {
          * int sum = 0;//Set breakpoints in this line
       for (int i = 0; i < 10 ; i++) {
            sum + = i;
      }
        system.out.println (sum);
  }

When I set a conditional breakpoint, I write the following: Sum > 5. Breakpoints are set on a line that defines sum, stating that sum is undefined when debugging, and that the breakpoint property set to Sum>5--sum is not defined how can I assign a value? So wrong.

3 If you want to modify the code/set the conditional Breakpoint/breakpoint property values in the properties, be sure to stop the debug, then set, and then restart the debug

This will take effect.

4 Introduction to several attributes in breakpoint properties

Right-- Breakpoint Properties will enter the interface at the breakpoint:

             

3 Modifying the value of a variable

When do you use it? For example, if there is a problem with the value of one of the variables in the program, we need to modify it to make the program run.

(Click ChangeValue to pop up the dialog box)

4 several buttons to be mastered for debugging
a:resume | [ri ' zju:m] (restart) executes the next breakpoint directly after the click, if the next loop is executed in the loop.
B:step into step-by-step execution
C:step over a row of rows, the child function is also seen as a step (the main () call to print () is skipped with step over once)
D:drop to frame.
The main purpose is
All variable states are quickly restored to the beginning of the method and re-executed again, that can be over and over again in the one you care about
In the context of multiple debugging (combined with changing the value of variables and other functions), and do not have to debug where to go again. Of course
The side effects of the original execution process are irreversible (for example, you inserted a record into the database).

How to use:
The fallback for this debug is not omnipotent and can only be rolled back in the current thread's stack frame, and can be returned to the current thread at most
At the beginning of the call. On fallback, right-click on the thread method that requires fallback and select Drop to Frame

& nbsp;  5 Exception Breakpoint-helps us determine the location of the exception.
         location:  the upper-right corner of the debug interface, breakpoints a column--add Java excption breakpoint
         ,
         Often encounter some anomalies, and then the program exits, to find the place where the exception occurred is more difficult, Fortunately, you can hit an exception breakpoint,
         This way, when an exception occurs, the code stops at the occurrence of the exception,
         should be helpful when locating problems.
        
         How to use?
            1 Find the name of the exception in the console error message
            2 Open the Debug interface after copying, adding an exception breakpoint with the same name
            3 ( If you just start debugging simply to find out where the exception appears, without adding a breakpoint, the program stops at the point where the exception occurs.
        
    6 Expressions (very flexible!) Strong Push! )

expressions Column
         to see the values of each variable by adding an expression Expressions.
         (Add a new watch expression) symbol.
        
         Write an expression that represents a value: Sum, sum*3; Getsum ( ); Wait.
         Click OK to see the results as follows: (Viewing the results is quite convenient, personal feeling is more useful than the variable window!)
        
         is more powerful than Varibles:
             1 view values in a more flexible way, depending on the expression, you can view any value. For example: variables, variable expressions, the return value of the method
             The expression of the return value of the method, and so on. Sum, sum*3; Getsum (); Printrestule () et cetera          

resources include:

1 Dark Horse programmer Xu Gang teacher video

2 http://eggbucket.iteye.com/blog/1381610 (myeclipse commissioning Technology)

Elaborate myeclipse debugging

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.