Debugging is the skill of finding out why a program does not do what you expected. It is a daily task for every developer, and a calm, step-by-step method saves hours.
1. Reproduce the problem
Find the exact steps and input that cause the error. A bug you cannot repeat is very hard to fix.
2. Read the error message and stack trace
The stack trace shows the line where the error happened and the calls that led there. Start at the first line that belongs to your own code.
3. Use breakpoints
In an IDE such as IntelliJ or Eclipse, set a breakpoint, run in debug mode and step through the code. Watch the values of variables change.
4. Change one thing at a time
Make one change, test again and note the result. Several changes at once hide which one fixed the problem.
5. Write a test for the bug
Once fixed, add a unit test that would have caught it, so it does not come back.
Next step: see our Java Full Stack course at ScholarLogic, or book a free demo class. A counsellor will share the fee and the next batch dates.
