Debug Java Summary inside eclipse

Source: Internet
Author: User
Tags tomcat server

     ? The so-called "工欲善其事 its prerequisite", will use Eclipse to debug can help identify and solve the application defects, but also can help us to read and understand some of the source code is very helpful. Can greatly improve our efficiency. ?

1. Basic knowledge, familiar with debug view

recognize the debug view, the Red part box is the thread stack view, the yellow part box is an expression, a breakpoint, a variable view, the blue part is the Code view .


Thread Stack View

Describe the meanings of these buttons separately:

1. Indicates that the current implementation continues to run until the next breakpoint, and the shortcut key is F8.

2. Interrupt the entire process

3. The current method is entered, and the shortcut key is F5.

4. Indicates that the next line of code is running, and the shortcut key is F6.

5. Means to exit the current method, return to the call layer, and the shortcut key to F7.

6. Represents the stack of the current thread, from which you can see what code is running, and the entire calling procedure, along with the code line number



Variable view

1. For the variable name view, displays all accessible instance variables and local variables in the current line of code

2. Show all the variable values

3. Variable values can be changed by this window



Breakpoint View

1. Show All Breakpoints

2. Disable the selected port in the current window 1 (you can see that all breakpoints on your own window have been slashed) and click Enable again.

3. Exception Breakpoint



An expression view

Expression view: The expression view is a more common view of the debug process, you can observe some of the variables you are interested in, you can add some of your own expressions, or you can see the results of a line of code running.

1. Expressions

2. Click this to add an expression



Code view

Code view: Used to display the specific code. Where the green part refers to the code that is currently going to be executed


2. Some very useful debugging small method

2.1Drop to Frame-fallback to the beginning of the function

This can be skipped to the beginning of the call stack frame, and the value of the variable will return to the original. Depending on the depth of the stack, the main use of this feature is that all variable states can quickly return to the way the method starts executing, and then you can do it over and over again, so that you can debug multiple times in your area of interest, but there are some side effects during execution. For example, the data inserted into the database can not be deleted!

2.2 Changing the value of a variable

During the debugging process, we can modify the value of the variable. Select a variable and then enter the variable view (Variables view), and enter the value in its corresponding value joins according to the variable type.


2.3 Item Breakpoint

A conditional breakpoint, as the name implies, is a breakpoint with a certain condition, and the code will stop when it runs to the breakpoint only if the user set conditions are met.

Right-click at the breakpoint and select the last "Breakpoint Properties"


The property interface of the breakpoint and the meaning of each option,

2.4 Exception Breakpoint

often meet some anomalies, and then the program will exit, to find the place where the exception occurred is more difficult, fortunately, can hit an abnormal breakpoint,


We have added a Nullpointexception exception breakpoint, and when the exception occurs, the code stops at the occurrence of the exception and should be helpful when locating the problem.

2.5 Single Step Filtration

The single-step filtering scenario is when we use F5 to follow a method's interior, often following some of the methods we decide we don't need to see.

This.gettradedetail (UID, itemstr.substring (0,5))

such as this line of code, want to F5 into the gettradedetail interior, Will first execute the Itemstr.substring method, will first enter the substring method, and this method is the JDK string method, determined that no problem, no need to care, single-step filtering is to skip the methods we want to ignore directly to the inside of the target method of a debug technique.

In Window > Preferencesjava > Debug > Step Filtering settings Filter, you can select the packages and classes that need to be filtered out. Also make sure that you enable single-step filtering in the debug view, such as. This filter function is used when you use single-step debugging.

is the filter configuration, which is typical of some of the JDK's classes and package configurations. is to open the single-step filter at debug time, otherwise it will not take effect .

Turn on single-step filtering

These small debugging methods in our debugging project can indeed give us a lot of help, we must learn.

3 Remote Debugging

This debugging method in our actual work development used very much, especially in our Java Web Development, our program to run under Linux, but we write code, testing, generally under windows, but we want to remotely debug the server code, especially out of the bug , we have no problem locally, but there is always a problem in the test environment.       

Remote debug: Remote Debug, as the name implies, is able to debug any Java on the remote operating system, but only if there is a local need for synchronized code.

3.1 Eclipse remote debugging Linux under Tomcat

see a lot of people, set this, set that, in fact, not so troublesome, because the Tomcat server has built-in JPDA support (Java JPDA remote Debugging program, JPDA is the JDK's own remote debugging mechanism) ?

Operation under Linux:

1. Stop Tomcat first

2. Have tomcat run in a way that can be debugged remotely.

go to the Tomcat Bin directory and execute the following command   

catalina.sh JPDA Start

Operations under Windows

1. Open the Debug Configurations view

2. Right-click on the remote Java application,

New

3. Select Source Engineering

4. Enter remote IP and port, port as service end of the $debug_port, click OK.

3.2 When our remote connection is debug, the following error may be reported:

The reason is that we already have a remote connection, and we go into the debug view and turn it off.

1. Open Debug View, Window----Open Perspective----Debug, the Debug view can be opened

2. Close this remote connection

Click the button below to close the remote debugging connection

At this point, the basic Eclipse debugging tips are done!

Debug Java Summary inside 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.