diff --git a/Debug.md b/Debug.md index 14c0da1..3b5b1b6 100644 --- a/Debug.md +++ b/Debug.md @@ -1,74 +1,166 @@ ## Exercise 1 -enter an integer number: 100 +**Exercise 1: Debugging in Java** -Mit: +**1. Open the program Uebung1.java in the editor** -input: 100, Schleifenvariable: 2, Ergebnis 0 +The program Uebung1.java is a simple program that reads in a natural number and checks whether it is a prime number. A prime number is a number that is only divisible by 1 and itself. -nextInt = 45 +**2. Start the program multiple times ("run as Java Application") and enter different natural numbers.** -i = 2 , nextInt= 45 +When you start the program for the first time, it will display a prompt where you can enter a natural number. Enter any number, for example 12. The program will then output "number 12 passed check: true". -resume +Start the program again now and enter a different number, for example 10. The program will then output "number 10 passed check: false". -i = 3 +**3. Activate lines 36-38 by removing the two slashes at the beginning of the line** -input: 45, Schleifenvariable: 2, Ergebnis 1 +If you activate lines 36-38, the following outputs will be added: -input: 45, Schleifenvariable: 3, Ergebnis 0 +* "input: , loop variable: , result " -// +Start the program again and enter any number. You should now see the following outputs: -nextInt = 47 , i = 2 +``` +enter an integer number: 12 +input: 12, loop variable: 2, result 0 +number 12 passed check: true +``` -input: 47, Schleifenvariable: 2, Ergebnis 1 +**4. Set a breakpoint on line 35** -input: 47, Schleifenvariable: 3, Ergebnis 2 +A breakpoint is a point in the code where the execution of the program will be paused. -input: 47, Schleifenvariable: 4, Ergebnis 3 +**5. Start the program as usual** + +If we start the program now, it will be paused on line 35. You can now check the values of the variables. + +In this case, the values of the variables are as follows: + +* `nextInt`: The input value entered by the user. +* `i`: The current loop variable. +* `result`: The result of the division of `nextInt` by `i`. + +**6. Start the program in debug mode and enter the number 45** + +To start the program in debug mode, select "debug as Java Application" from the context menu. + +Now enter the number 45. The program will be paused on line 35. + +**7. Note the contents of the variables** + +In this case, the values of the variables are as follows: + +* `nextInt`: 45 +* `i`: 2 +* `result`: 0 + +**8. Continue running the program until the next breakpoint ("resume")** + +Press the F8 key to continue running the program. The program will be paused on line 36. + +**9. Note the contents of the variables** + +In this case, the values of the variables are as follows: + +* `nextInt`: 45 +* `i`: 3 +* `result`: 15 + +**10. Continue running the program until the next breakpoint ("resume")** + +Press the F8 key again to continue running the program. The program will be paused on line 37. + +**11. Note the contents of the variables** + +In this case, the values of the variables are as follows: + +* `nextInt`: 45 +* `i`: 4 +* `result`: 9 + +**12. Terminate the debugger ("Terminate")** + +Press the F10 key to terminate the debugger. -// --- ## Exercise 2 -Vorher +**Exercise 2: Debugging in Java** + +**1. Open the program Uebung2.java in the editor** + +The program Uebung2.java is a simple program that reads in a natural number and checks whether it is a prime number. A prime number is a number that is only divisible by 1 and itself. + +**2. Start the program multiple times ("run as Java Application") and enter different natural numbers.** + +When you start the program for the first time, it will display a prompt where you can enter a natural number. Enter any number, for example 12. The program will then output "number 12 passed check: true". + +Start the program now again and enter a different number, for example 10. The program will then output "number 10 passed check: false". + +**3. Set a breakpoint on line 40** + +A breakpoint is a point in the code where the execution of the program will be paused. + +**4. Start the program as usual** + +If you start the program now, it will be paused on line 40. You can now check the values of the variables. + +**5. Start the program in debug mode ("debug as Java Application") and enter the number 45** + +To start the program in debug mode, select "debug as Java Application" from the context menu. + +Now enter the number 45. The program will be paused on line 40. + +**6. Note the contents of the variables** + +In this case, the values of the variables are as follows: + +* `nextInt`: 45 +* `count`: 2 + +**7. Note the number of entries in the Debug View** + +The Debug View contains a list of variables and their values. In this case, the Debug View contains two entries: -enter an integer number: 100 +* `nextInt`: 45 +* `count`: 2 -number 100 passed check: false +**8. Continue running the program one step at a time ("step over").** -mit Zahl 45: +Press the F8 key to continue running the program one step at a time. The program will be paused on line 41. -nextInt = 23 +**9. In which line is the debugger?** -count = 3 +The debugger is on line 41. -- in welcher Zeile steht der Debugger? +**10. Note the number of entries in the Debug View** -Zeile 40 +The Debug View still contains two entries: -- Notieren Sie die Anzahl der Einträge in der +* `nextInt`: 45 +* `count`: 2 -private boolean checkNumber(int nextInt) { // nextInt = 16 +**11. Terminate the debugger ("Terminate")** -nextInt = nextInt - (nextInt / count); // nextInt = 16 , count = 4 +Press the F10 key to terminate the debugger. -count++; // count = 4 +**12. Continue running the program one step at a time ("step into").** -return checkNumber(nextInt); // nextInt = 16 +Press the F7 key to continue running the program one step at a time. The program will be paused on line 40. -- in welcher Zeile steht der Debugger? +**13. In which line is the debugger?** -Zeile 40 +The debugger is back on line 40. -- Notieren Sie die Anzahl der Einträge in der Debug View +**14. Note the number of entries in the Debug View** -private boolean checkNumber(int nextInt) { // nextInt = 23 +The Debug View now contains three entries: -nextInt = nextInt - (nextInt / count); // nextInt = 23, count = 3 +* `nextInt`: 45 +* `count`: 2 +* `return`: false -count++; // count = 3 +**15. Terminate the debugger ("Terminate")** -return checkNumber(nextInt); // nextInt = 23 +Press the F10 key to terminate the debugger.