Eclipse set conditional Breakpoints Debug Java programs

Source: Internet
Author: User

Programmers debug code often uses breakpoints, but many people may not have used conditional breakpoints, so when will need to use conditional breakpoints.

1, for loop comparison more times, want to let the For loop stop at the specified number of loops at the

2, you want to run at the same time the code environment on their own debugging, but also does not affect the access of others

At this time you can choose to use conditional breakpoints, conditional breakpoints, as the name implies is to meet certain conditions, the breakpoint will be enabled.

The following is an example of eclipse, which details how to set a conditional breakpoint: 1. Sample code:

Class person{public
	String firstName;
	Public String lastName;
	public int age;
	Public person (string firstName, string lastName, int age) {
		this.firstname = firstName;
		This.lastname = LastName;
		This.age = age;
	}
}
public class test11{public
	static void Main (String args[]) {person
		people[] = new person[]{
			new Person ("T Ed "," Neward "," a "," New Person "
			(" Charlotte "," Neward "," a "),
			New Person (" Michael "," Neward ",),
			new Person ("Matthew", "Neward",)
		};
		for (person p:people) {
			System.out.println (p);}}}

2, Breakpoint set: 2.1 hit a breakpoint inside the for loop, then right click on the breakpoint, click on the bottom of the pop-up "Breakpoint Properties"


2.2 as shown in the following figure, select Conditional, when the default suspend when True the radio button is selected, that is, when the condition is true, the breakpoint will stop


2.3 In the bottom of the blank as input conditions conditional, can be as convenient as writing Java code, as well as the hint message:



3, breakpoint debugging

After entering the condition, click the Save button to save the then you can start the debug code as usual, only your breakpoint will stop when the condition is satisfied, like the following, look at the console below, the first condition of the data has been printed out, parked in the p.age=13 record, is not very convenient. Now use it. The conditional expression of a conditional breakpoint also supports complex combinations, just as an expression that writes an if () condition in code.


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.