1.1 Eclipse Breakpoint Debugging Overview
Breakpoints debugging in Eclipse can see the program's execution process and bugs in the resolver
1.2 Eclipse Breakpoint Debugging common operations:
A: What is a breakpoint:
is a marker, where to start.
B: How to set Breakpoints:
Where you want to see the program, you just double-click on the left side of the active program.
C: Where to set breakpoints:
where not to point.
Currently: we add on the first valid statement of each method.
D: How to run the program after setting breakpoints:
Right--Debug as--Java application
E: See which places:
Debug: Where to test breakpoints
In this place, remember the F6, or click also can. See the execution of a row at a time.
Variables: Viewing variable variations of a program
Fordemo: The source file being viewed
Console: Consoles
F: How to go to breakpoints:
Double-click again to
Find the debug view, variables interface, find breakpoints, and click, then see all the breakpoints, and finally click on that double fork.
1.2.1 Case Code One:
package com.itheima;/* * 断点调试: * A:查看程序的执行流程 * B:调试程序 * * 断点: * 其实就是一个标记 * * 在哪里加呢? * 想加哪里就加哪里,一般是加在我们看不懂的地方 * * 如何加呢? * 在代码区域的最左边双击即可 * * 如何运行加断点的程序呢? * 代码区域 -- 右键 -- Debug as -- Java Application * 会弹出一个页面让我们选择是否进入debug模式,选择yes。 * * 如何让程序往下执行呢? * Step Over 执行下一步 * F6 * * 看那些区域呢? * 代码区域:看程序的执行步骤 * Debug区域:看程序的执行步骤 * Variables:看变量的创建,赋值,销毁等 * Console:看程序的输入和输出 * * 如何去除断点: * A:把加断点的动作再来一遍 * B:在debug视图中,找到Breakpoints,选中断点,点击双x即可 */public class DebugDemo {public static void main(String[] args) {int a = 10;int b = 20;int c = a + b;System.out.println(c);}}
1.3 Breakpoint Debugging Practice 1.3.1 Case Code two:
package com.itheima;/* * 需求:看循环的执行流程(1-5求和案例) */public class DebugTest {public static void main(String[] args) {// 定义求和变量int sum = 0;// 循环获取每一个数据for (int x = 1; x <= 5; x++) {sum += x;}System.out.println("sum:" + sum);}}
1.3.2 Case Code Three:
package com.itheima;import java.util.Scanner;/* * 需求:看方法的调用流程 * * 有方法调用的时候,要想看到完整的流程,每个方法都要加断点,建议方法进入的第一条有效语句加断点 */public class DebugTest2 {public static void main(String[] args) {// 创建对象Scanner sc = new Scanner(System.in);// 接收数据System.out.println("请输入第一个数据:");int a = sc.nextInt();System.out.println("请输入第二个数据:");int b = sc.nextInt();// 调用方法int result = sum(a, b);// 输出结果System.out.println("result:" + result);}// 求和方法public static int sum(int a, int b) {return a + b;}}
1.3.3 Case Code Four:
package com.itheima;/* * 参数是基本数据类型: * 形式参数的改变不影响实际参数。 */public class DebugTest3 {public static void main(String[] args) {int a = 10;int b = 20;System.out.println("a:" + a + ",b:" + b);change(a, b);System.out.println("a:" + a + ",b:" + b);}public static void change(int a, int b) {System.out.println("a:" + a + ",b:" + b);a = b;b = a + b;System.out.println("a:" + a + ",b:" + b);}}
1.3.4 Case Code Five:
package com.itheima;/* * 参数是基本数据类型: * 形式参数的改变不影响实际参数。 */public class DebugTest3 {public static void main(String[] args) {int a = 10;int b = 20;System.out.println("a:" + a + ",b:" + b);change(a, b);System.out.println("a:" + a + ",b:" + b);}public static void change(int a, int b) {System.out.println("a:" + a + ",b:" + b);a = b;b = a + b;System.out.println("a:" + a + ",b:" + b);}}
1th Eclipse Breakpoint Debugging