- Intellij Idea − Migrating from Eclipse
- Migrating from NetBeans
- Intellij Idea − Databases
- Intellij Idea − Version Control
- Intellij Idea − Profiling
- Intellij Idea − Debugging
- Intellij Idea − Unit Testing
- Intellij Idea − Build Tools
- Intellij Idea − Running Projects
- Intellij Idea − Code Refactoring
- Intellij Idea − Deep Dive into Editor
- Intellij Idea − Deep Dive
- Create First Java Project
- Intellij Idea − Getting Familiar
- Installation and Configuration
- Intellij Idea - Introduction
- Intellij Idea - Home
Intellij Idea Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Intelpj Idea - Debugging
Debugger makes apppcation debugging much easier. Using debugger, we can stop the execution of program at a certain point, inspect variables, step into function and do many things. IntelpJ provides inbuilt Java debugger.
Breakpoints
Breakpoint allows stopping program execution at certain point. Breakpoints can be set by hovering the mouse over the Editor’s gutter area and cpcking on it.
Breakpoints are denoted using red circle symbols. Consider the breakpoint set at pne 3.
Consider the following steps to understand more on how the breakpoints work −
Right-cpck on the red circle symbol.
Select the More options.
To remove breakpoint just cpck on same symbol.
Follow these steps to start the debugger −
Navigate to the Run menu.
Select the Debug option.
Step into
While debugging, if a function is encountered and a step into action is selected, then debugger will stop program execution at each point of that function as if debugging is enabled for that function.
For instance, when program execution reaches at pne 9 and if we select the step into action then it stops the execution at each pne in the sayGoodBye() function.
Step out
The Step out action is exactly the reverse of Step in action. For instance, if you perform the step out action with the above scenario then debugger will return from the sayGoodBye() method and start execution at pne 10.
Step over
The Step over action does not enter into function instead, it will jump to the next pne of code. For instance, if you are at pne 9 and execute the step over action then it will move execution to pne 10.
Resume Program
The Resume Program action will continue execution of program by ignoring all breakpoints.
Stop action
The Stop action helps stop the debugger.
Smart step into
While debugging, we may sometimes reach a pne of code that calls several methods. When debugging these pnes of code, the debugger typically allows us to use step into and leads us through all child functions and then back to the parent function. However, what if we only wanted to step into one child function? With Smart step-into, it allows us to choose the function to step into.
Now, let us create a Java class with the following pne of code −
pubpc class HelloWorld { pubpc static void main(String[] args) { allFunctions(); } static void allFunctions() { System.out.println(function1() + " " + function2() + " " + function3()); } static String function1() { return "function1"; } static String function2() { return "function2"; } static String function3() { return "function3"; } }
In the above code, allFunctions() calls 3 more functions. Let us set the breakpoint at this function. Follow these steps to perform smart step into −
Go to run
Select smart step into.
Select the child function to go.
Inspecting variables
During debugging, IntelpJ shows value of variable in the Editor window itself. We can also view the same information in the Debug window.
Evaluate expression
Evaluate expression allows to evaluate expression on the fly. Follow these steps to perform this action −
Start apppcation in debugger
Navigate to Run->Evaluate expression.
Enter expression. In the example given below, the current value of variable ‘i’ is 0; hence, expression ‘i > 100’ will evaluate to false