1. first search for the syntax errors
2. swith to debug mode and Search for for runtime errors and logic errors:
I will show you HOW TO USE THE TOOLS by using following example code:
If you calculate by hand: 2 + 5 – 1, this should be 6. However, the program gives the output -4.
To analyse where this goes wrong, use the debug tool:
Beforehand you should already have searched on syntax errors as described above.
- Switch to “Debug Mode”
- Create breakpoints; Mark the parts you want to analyse, by double clicking on the left side bar:
-
Press “Debug as” Press or press directly the symbol if java already selected the right project - By using these tools, it is possible to go through the code:
Key Description F5 Executes selected line, whilegoing step-by-step into the line F6 Executes selected line, withoutgoing step-by-step into the line F7 Stepping out of the selected method F8 Resume program, until next breakpoint ** This is a “going back” tool. For example, useful when you want to go back in a method - This window “variables” shows the variables you have defined in the program
After debugging line 6 of the method add, the answer is -3. This is already a weird result. Because add should give 2 + 5 = 7. - Therefore, look at the method add, which shows what the mistake was. In this case a logic error. The “-” sign is wrong, because it is an add function.
- After changing the add-function the program gives the desired result.