"Hi, Amigo!"
"Hi, Ellie! Did you do your hair differently? It looks good on you!"
"Really? Thanks!"
"Today I'm going to tell you about working in IntelliJ IDEA."
"But I've been using it for quite a while now."
"Yes, I know. That's why I want to tell you about a few things that make life much simpler."
"The first and most important thing that every developer must be able to do is debug programs. 'Bug' is programmer slang for errors in a program."
There are two modes for running your application within IntelliJ IDEA.
Button | Mode |
---|---|
Run the program normally | |
Run the program in debug mode |
"Ah. The button shaped like a bug is for debugging. That's awesome."
"Here's the most important thing! When running in debug mode, you can execute the application one step at a time. One line at a time."
"And the most important part of debugging is breakpoints."
"You can put a BreakPoint on any line of code. A program running in debug mode will reach this point and stop. To add a breakpoint, place your cursor on the desired line and press Ctrl+F8. To remove it, press Ctrl+F8 again."
"To continue executing the program until the next breakpoint, press F5."
"To continue stepping through the program, press F7 or F8."
"If you press F7, the debugger will step into methods when they are called."
"If you press F8, a method call will be treated as a single step. The debugger won't step into methods."
"Can you explain that last part in a little more detail?"
"Sure. Here, copy this code and I'll use it as an example as I explain what to do:"
package com.codegym.test;
public class MainClass
{
public static void main(String[] args)
{
int n = 100;
int sum = 0;
for (int i = 0; i< n; i++)
{
sum += i;
}
System.out.println(sum);
}
}
"In this example, we're simply calculating the sum of numbers from 0 to n."
How to place a breakpoint
"Option 1: Put the cursor on the desired line and press Ctrl+F8"
"Option 2: Left-click the desired line."
How to place a breakpoint | Result |
---|---|
"To remove a breakpoint, click the red circle or press Ctrl+F8."
"Now we start the program by clicking the debug button."
"You should get something like this:"
"All of the code has been executed up to the blue line. The line highlighted in blue hasn't been executed yet."
"Press F8 to execute it. There you should end up with something like the picture below:"
"Red indicates a breakpoint
"Blue indicates the current debug line"
"Let's replace the number 100 in the code with a 5, and try running the entire program one line at a time. Here's the sequence of steps:"
"The first step is the line highlighted in red."
"Blank lines as well as curly braces are skipped, since there's no code there."
"Now make the program a little more complicated, and I'll show you the difference between F7 and F8."
"If you press F8, then you execute the current line in a single step."
"If you press F7 and the current line is a method call, then you'll 'step into' it and can execute it one line at a time."
"So, the difference is whether we step into the method."
"Yep."
"Can I use F7 and F8? In other words, can I skip some methods that aren't of interest to me, but step into others?"
"Yes."
GO TO FULL VERSION