Debugging in STS
Posted By : Pankaj Garg | 29-Aug-2022
Debugging in Spring Tool Suite
To understand what is debugging, let’s first understand what a bug is.
A bug is an error, fault, or flaw in a design, development, or operation of Computer Software that causes misbehavior or incorrect or unexpected results. It is not any type of compile-time error or run-time error. The code will simply run and produces a result, but the result may be unexpected or not what we needed, and it will behave in an unintended way.
What causes a bug in a code?
A bug can be created when writing code. It may be due to incorrect communication about the project and its requirements or I can also be created when the code is written without considering all the possible case scenarios, or sometimes when things were not required when the code was written, but now when the projects scale up, it creates a new bug.
A bug is always unchecked, and they are sometimes very hard to find; for instance, a user enters an input that the programmer did not expect. It also becomes hard to locate a bug when two or three instances are running together, and you don’t know which of the instance caused an issue.
What is Debugging and its need?
Debugging is the process of finding the problem within a code and trying to solve it with case scenarios or checking which part of the code caused the bug.
We need debugging so that the problem can be cured within the code, the results a programmer is expecting can be found, and the project will run smoothly back again. A programmer can show an exception occurred when entering a certain input or certain format to enter a value. There are many reasons to debug a code.
Debugging can be a very hard and tiring process as a programmer does not understands what causes the problem initially. Nowadays, IDEs are powerful enough to help the programmer debug and find the problem with the code and fix the code.
Debugging in Spring Tool Suite.
1. Setting up breakpoints
Break points are the pointers which are put on the line where we want the code to stop/pause the process unless or until we resume back to the normal running state of a program.
Right-click on the line where you want the program to stop.
Click on toggle breakpoint.
2. Run the program in Debug mode.
Right-click on the project and click on debug and select Spring Boot Project.
A pop-up window will open, which will ask to change the perspective to the debug mode; click yes
3. Controls for programming Execution
F5 - Executes the current line and moves to the next line.
F6 – It is used to step over, i.e. to execute a method without stepping into the debugger.
F7- It is used to step out of the method/function to move to the line where it was previously.
F8 – It is used to resume the execution of the program to move to the next breakpoint, if any.
4. Breakpoint view
Later comes the breakpoint view on the extreme left side of the IDE, where all the lines where the breakpoint is added can be seen, and you can remove the breakpoints from those lines there as well
5. Changing the values
At any point while debugging, when you want to change the value that came, you can do that by hovering over it and changing the values to the desired. This also helps to see if there are any other values that you might wanna see or if there is a value you want to change to see what will happen if the only particular value could be changed.
6. Hovering to See the values
Hovering the cursor to the variables before or at the breakpoint and before the ending of the scope at the point where the breakpoint is stopped is used to check the value that the particular variable is showing is used to check if the desired value is coming till that point or not which can later be used to make different decisions in the code or to check at what point the values are changing their behaviour.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Pankaj Garg
Pankaj Garg is an experienced backend developer, specializing in Java and skilled in using technologies like MySQL, MongoDB, Spring Boot, Hibernate, and Spring Security. He has contributed to multiple internal and client projects. He has experience in creating POC projects such as Micro Services and Message Broker using Spring Security. He has also contributed to the development of the Book Store Management System, which utilizes Rest APIs to communicate from the database to the frontend, providing information on book availability. Along with his passion for coding, he also enjoys playing chess and badminton.