11
Oct

Debugging on Eclipse IDE – Basic Java Fast


Hi everyone, welcome to the Java course.
This video is going to go through the process of debugging for Eclipse, okay. So
I have a sample program here. I want the result at the end to show that “Now i is
4”, which is equal to the value shown on the text here, okay. But is it possible
for us to get i equals four as the final answer? Let me run it here. Yes, we can see
that the answer is not equal to what I want. “Now i is 3” becomes the answer
instead of i equals four, okay. so if I want to go through the problem with my code,
of course I can do the dry running. But when the code is a bit more complicated,
dry running is not that easy for me. So how can I make use of the debugging
functionalities of the Eclipse? I can do so by putting a breakpoint first. I can
put a pick a breakpoint next to line number six. How can I do that? I simply
double-click the margin on the left of the line numbers. Okay, there is a dot and
this dot is simply meaning the breakpoint And then I can go to Run, and then Debug Okay this statement is going to tell you
that you will switch to the Debug perspective. So let me switch it now Okay, this is the debugging environment
for Eclipse. How can I check the value of “i” when I run the code line by line?
I can go to here and press “step into” or F5 key. Initially here, “i” is zero, which
is simply the value coming from line number five. Okay, when I click “step into”, Okay, I will go to the another line
followed by the line having the break point. So this line is not executed yet.
When I press the “step into” key once more, the line here will be executed. So
let we do so now. Okay when I press the “step into” key, we can see that “i” is equal
to zero. So “i” is not equal to 3 in this situation. I don’t go to the breaking
action. Instead, I will leave … I will go away from the if statement to line number 10,
which give … tells me to increment i by 1. So at this stage, “i” is still equal to 0.
That means this line is not yet executed So when I press “step into” again, “i” would become one. That means this line is already executed. So now “i” becomes 1 and
“i”, which is equal to 1, is smaller than six. So this while loop condition still holds. I
will go into the while loop, “step into” again. Now 1 is not equal to 3. So
I don’t go to line number 8. Instead, I will go to line number 10 immediately. Yes,
at this stage “i” still equal to 1. And I press once more. “i” becomes 2, okay. Now “i”
is equal to 2. When I put the cursor next to the variable, I can see the value of
the variable, okay. So 2 is smaller than six. It means that this condition is
satisfied. I will go to the while loop again. So “step into”. So “i” is equal to 2 but it is not
equal to 3. So I don’t go to the breaking action. Instead I will good to line
number 10 Yes, okay let me press one more time. “i”
would become three now, okay. So “i” is equal to 3, which is smaller than 6. So
this while condition still holds. I will go into the while loop. Here, “i” is equal to 3,
and 3 is equal to 3. So in principle, I will go to the breaking statement on
line number 8. Let me see by clicking “step into” button. Okay I will go to the
“break” line here. Let me press once more Okay, the increment statement is not
executed because when I click on … on the “step into” button, I will go to the “break”
line, which tells me to leave the whole while loop. So I will simply go to the
printing statement on line number 12, okay So here, “i” is equal to 3. That’s why I
will get “Now i is 3” statement on the console. So let me step into this line again, again, again, again.
So you see that I’m going very deeply to the internal mechanism of the printing
action specified by the println command. If I want to ignore the specific
details of the printing action, I can click on “step over”, “step over” again. And I click on
“step over”, I will ignore one level of the internal mechanism of the printing
action indicated by the println command.
“step over” again, “step over” again. Okay, I can go outside the println mechanism. So I
can click on “step over” again, I will see the result printing on the console, okay.
So that’s why we can see the debugging process as
follows. When I click on “step into” I will go to the next line. When I click on “step
over”, I can get rid of the internal mechanism of the internal function
provided by Java. sS according to this debugging process, we can see that what I
need to change is this one: “i” equals four instead of “i” equals three. So when I want
to leave the debugging process, I can simply press terminate button here, ok. Ok,
the debugging process is now terminated And now I changed line line number seven to
“i” equals four. And let me run it normally Ok, the line is now correct. So that is
the process of doing the debugging on Eclipse. This is the end of the video. If
you have any questions about my video, feel free to leave your comments on the
comment section below the video. If you like this video, please give me a like
and please subscribe to my channel. Thank you for watching

Tags: , , , , , , , , , , , , , , , , , , , , ,

There are no comments yet

Why not be the first

Leave a Reply

Your email address will not be published. Required fields are marked *