Table of contents
1. Introduction to breakpoint debugging
2. F8 execute code line by line
4. How to look at the source code when debugging
5. How to directly execute to the next breakpoint F9
6. Use breakpoint debugging to view the dynamic binding mechanism
1. Introduction to breakpoint debugging
Breakpoint debugging refers to setting a breakpoint on a certain line of the program. When debugging, the program will stop when it runs to this line, and then you can debug step by step. During the debugging process, you can see the current value of each variable. If something goes wrong , when debugging to the wrong line of code, the error will be displayed and stop. Analyze to find this bug.
In the process of breakpoint debugging, it is the running state, and it is executed according to the running type of the object.
Breakpoint debugging is a skill that programmers must master. It can help us view the execution process of the underlying java source code and improve the programmer's Java level.
2. F8 execute code line by line
code (2-1)
public class Text1 {
public static void main(String[] args) {
int sum=0;
for (int i = 1; i <= 10; i++) {
sum+=i;
}
System.out.println(sum);
}
}
Demo:
F8 execute code line by line
3. Debug encounter exception
public class Text {
public static void main(String[] args) {
int[] arr={1,2,3};
for (int i = 0; i <= arr.length; i++) {
System.out.println(arr[i]);
}
}
}
Demo:
Array out of bounds exception
4. How to look at the source code when debugging
Configuration: Setting->Build, Execution, Deployment->Debugger->Stepping, uncheck java.*, javax.* in Do not step into the classes, and others are optional.
How to debug and see the source code configuration
public static void main(String[] args) {
int[] arr={0,-1,100,6,7};
Arrays.sort(arr);
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
Code (4-1)
see source code demo
5. How to directly execute to the next breakpoint F9
code (5-1)
public static void main(String[] args) {
int[] arr={0,-1,100,6,7};
Arrays.sort(arr);
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
System.out.println("a");
System.out.println("b");
System.out.println("c");
System.out.println("e");
System.out.println("f");
System.out.println("g");
System.out.println("h");
}
Demo:
How to execute directly to the next breakpoint
6. Use breakpoint debugging to view the dynamic binding mechanism
Code (6-1)
public class Text {
public static void main(String[] args) {
A a=new B();
a.a();
}
}
class A{
public void a(){
ab();
}
public void ab(){
System.out.println("class A的方法");
}
}
class B extends A{
public void ab(){
System.out.println("class B的方法");
}
}
Demo:
Use breakpoint debugging to view the dynamic binding mechanism
The above is my personal sharing, if you have any questions, welcome to discuss! ! !
I've seen this, why don't you pay attention and give a free like