Let's not look at a very important I know very interesting topic. 2
It's about losing eclipses debugger as the name suggests a debugger is a tool that aids in application 3
debugging. 4
That is if there is a bug which is nothing but a defect in your application then you would debug it 5
. 6
So if you see any defects in your application then you can run the debugger to investigate the issue 7
and then identify the exact problem area and then subsequently fix it. 8
The application will be run by more when you're running the debugger debugger is also useful in understanding 9
the program flow. 10
So if you're looking at some code that you are not familiar with then you can use a debugger to get 11
a good understanding of how the program works. 12
That's a really effective way to understand code written by someone else in this lesson we will learn 13
how to use a debugger effectively. 14
So let's get started now. 15
Good debugging application. 16
The first thing you would do is set one or more breakpoints a break point is the place with the debugger 17
with boss. 18
So when you start a debugger it would run the application on would stop at the first break point. 19
So a break point is essentially the point where you want to investigate the code. 20
So let's just go ahead and place on a breakpoint in the student test class. 21
So here we are in the Student class and we are iterating over all the students and printing the name 22
and gender. 23
So let's just go ahead and place our break for point here in line 35. 24
And all we need to do is just double click here. 25
And that's a break point. 26
Now if you want to remove it just double click again. 27
OK. 28
So let's just go ahead double quick here and to start the debugger all we need to do is press this button 29
over here ARE WE CAN DO IT RIGHT CLICK HERE answered run debug ass java application. 30
Now if you do run as to our application it would simply run the application without the debugger. 31
OK so let's just go here. 32
Press this button here. 33
Now what happened was earlier we were in Djala perspective now because we have started a debug session 34
it opened a debug perspective. 35
OK so we are here in the book Wisbech. 36
Sometimes this would invoke a pop up on you with a dialog and you would have to hit okay for that. 37
And if that happens or you can go ahead and do it. 38
OK. 39
So here we are in debug perspective. 40
And it shows different views here. 41
So this is the debug view here. 42
This is a debug view. 43
And here are sites variables view. 44
I will get back to that later. 45
And here is the editor. 46
And here is a concern as application is running we will see the output here. 47
So let's just go ahead and close this outline. 48
So the debugger has started on it has stopped at the first big point here. 49
So that's like totally fine. 50
And here within the debug view what this means is it's telling. 51
This is called It's a stack frame and it is telling that we are inside the main method at line 35 and 52
these are all the local variables of attend the main matter first. 53
I would like to talk about is about these three features here. 54
So let's just go and then this is called a step into step over step here. 55
And so let's just begin with this step over which has a shortcut of F 6 also and what it means is what 56
exactly the current line in the statement. 57
And it would more move to the next statement. 58
OK so let's just do that. 59
So as you can see we are at line 36 now and even here it has changed to 36. 60
Now let's look at the variables here. 61
So we just executed this here. 62
This line the statement in line 35 on its name. 63
And if you see a free highlighted here where here Howard the name variable we can see that it is the 64
name is initialized to John. 65
OK. 66
So this is a student and you can see the same output here also name value is Jo-Anne. 67
OK. 68
Now let's step over once again. 69
So we don't we have just executed the second statement and gender is male ungenerous male here so new 70
variable got created. 71
And here is a method right. 72
So if we want to investigate the matter what we can do is we can step into. 73
Which means that we are telling the debugger to step into that matter. 74
So let's just do that. 75
Now here we are in the first statement of the method and you can see that this has changed do you know 76
the main method the stack frame corresponding to main method of went down and then we have a new stack 77
frame corresponding to the numerator. 78
So it's here right now and we are at line 48. 79
And these are the variables corresponding to the numerator. 80
OK. 81
So let's just head step or. 82
And you can see that the output is also getting printed here. 83
The new output in the console let's it step on again and let's step or again. 84
So we will go back and the control comes here and then it goes with the next declaration. 85
So let's head control stapler. 86
This is the second student step over this time not just do a step or so the loop continues again and 87
it's good booze once again step over step or step over. 88
Let's do a step into here and one other thing I wanted to show you here as it's printing the name and 89
gender. 90
But you can see that it's also blending the student also so if you click on this student as here it's 91
the local variable of the for loop. 92
So if you click click here you can see the all the elements of the student object itself. 93
OK. 94
So you can see that ID's thousand three name is Anita. 95
So these are all the variables within the student. 96
So here variables would show both residue variables as well as object references. 97
Now let's go here step into. 98
Now let's look at step written step written words simply execute the methhead and it would take the 99
control back to the caller and it would move to the next statement after the after the Invoke in location 100
statement. 101
OK so let's just head this here now. 102
So the control came back here and it went to the next iteration. 103
OK. 104
So that's separate. 105
Now let's do one more time step or step or step or up do step or where. 106
Now here we are at the closing brace at this point it doesn't matter whether we step over or step breakdown 107
or step in. 108
So all three would work in the same way sort of just head step over. 109
And so since we have four students now when I hit a step or so control goes back here to set M.. 110
So we don't how any other any any other big points we can search more than one break point. 111
And also one other thing is when we vent here around when we were in print method. 112
So if we had then we you know when we do step down here it was returning the control back to the calling 113
motard But if there was any other break point in between then it would stop at the big point. 114
OK so if there is no magic wand you would call the control would go back with a calling method. 115
OK. 116
Now let's go back to the matter let's just had this button. 117
So back to this matter. 118
Now if you do step or can just took over. 119
Now let's see if you're done with your investigation you can either stop here dominate. 120
You can terminate all you consider is you. 121
So you can resume the control would raise your hand. 122
It would stop at the next break point. 123
OK so let's just head this and we are done with the debugging session. 124
Now let's look at something interesting. 125
So let's just go up here. 126
The student won. 127
Let's get another break point here. 128
So here we are creating a student instance. 129
OK. 130
And this is the first Torent instance. 131
So we have two break points in our student test at line 13 on line five. 132
So let's just go ahead and head and de-bug once again. 133
So the debugger pauses here and let's So this is. 134
Here we are creating an instance. 135
So let's just go into this constructor here. 136
So let's step in do. 137
And here you see that it's loading this classic cordless classloader. 138
And even here here it says that in arts you can see the corresponding stack for him. 139
Let's get one more step in two and you'll see something else launcher Dark Glass string dark glass. 140
So what exactly is happening here. 141
So the thing that is happening is we are in walking we are creating the student instance for the very 142
first time. 143
And when that happens GBM first tries to load the Student class into the memory. 144
OK. 145
And that process is qualis glassblowing and we will see that in the GBM in dentals chapter. 146
So every time when we create a new instance every time as it classes access for the very first time 147
it has to be loaded into the memory. 148
And that's called class loading and that happens for the very first time. 149
Not for the second time. 150
So that's what is happening so when you see this all you can do is just click on separate and separate 151
and separate and separate. 152
So now we're back in the main matter and first instance has been created so let's just go to the second 153
instance. 154
Now let's head step into now as you can see it's no longer calling the class loading class. 155
The reason as class student is already in memory and JVM is simply using it to create the need to create 156
a new instance or an effect. 157
OK so what we saw happens only the very first time. 158
So that's the class drawing process. 159
So the first time it floats into the memory and from the second on time onwards it's just it just uses 160
the class from the memory. 161
Ok since it's already loaded into memory now we are here in this construct Let's head step over. 162
Now you'll see it's not going it's not executing the first statement but for some reason it's getting 163
here to the this statement where the gender variable and the student is getting initialized. 164
So what exactly is happening. 165
The thing is we know that within the constructor the first invocation statement would be a call to call 166
to the superclass constructor which is. 167
So we know that there is an super invocation statement. 168
So basically what happened was the object class got invoked under super invocation statement is an invisible 169
statement We know that. 170
And so that got in worked. 171
So the control window object it created an object instance and then it came back with a subclass which 172
is the student. 173
And then it started to initialize all these instance variables so that's what is happening here. 174
And we will examine it in more detail when we create the next instance so let's just head step over 175
so step or so we are here now. 176
Back. 177
So let's just go back Buist to pretend hits in do OK. 178
So this is the third student instance. 179
Now let's do another step in do. 180
And here we are. 181
So the object class got invoked. 182
So that's what has happened. 183
And we do step over. 184
So we are back in Student class. 185
Students take over step over OK so we. 186
So that's what is happening. 187
So there is an invisible super in waggish statement as we know. 188
And here is one more thing I want to point out as. 189
So here this is a statement. 190
So if we do step over it would execute this statement and move to the next statement. 191
But if had this been a method invocation then if we had step into it would go into the matter. 192
We know what we already know that. 193
But for this kind of statement which is not a method invocation statement it doesn't matter whether 194
it is step over or step into or even step into Would we have the same me. 195
It's just that if the statement involves him at that location then step in and do would really step 196
into that method. 197
OK so let's just step into the you see step into step into. 198
So that's what is happening here. 199
So there is no difference between step over and step into. 200
Now another thing I want to point as. 201
Let's say we came here to this particular statement and you just want to go back and do it go back in 202
time and you know or Buddha or de-bug once again into the beginning from the beginning of the matter 203
and that is all you need to do is just click on this. 204
Drop the frame and it would start again. 205
But the catch is that the ID variable got initialized 2003. 206
So the values are not reset. 207
It's just that the control goes back but the values the instance variable values are not initialized 208
or even the static variable values will not read or read initialized. 209
OK. 210
So let's just go do step over stick or stick or just of course the we're now ID would be 2004. 211
So that's the drop to frame on your JVM hostile supported in order for you to see these Eikon here. 212
So let's just do a step taken. 213
So here we are. 214
STUDENT 4 let's just take resume here. 215
So here we are in the for loop just took over. 216
Now another thing that we can do is here we have the name variable or the generated one. 217
You can also read said the value so the value is Jo-Anne. 218
Now let's say for example we want to see what happens if we change it to another. 219
OK so we can do that. 220
So you can just right click on Sid change value. 221
So from Joanne let's say you want to change it to null. 222
It's just a string. 223
So hit. 224
OK. 225
Now you can see that it is not a novel it's going to print. 226
Let's let's just step into print. 227
As you can see the print is not at all. 228
It's printing now here. 229
So it's just written soon it's just finished a.. 230
Now one final thing I want to show is let's just go here. 231
So let's just say we want to get it. 232
I mean if we hit resume it's going to finish right. 233
Because there is no break point. 234
But let's say we want to stop here. 235
There is no break point but we still want to stop here at some point in the future. 236
So what we can do is just put your you know just going near that statement going to that line and just 237
hit Control are and you can see the control jumps to that particular statement and it exiguous everything 238
in between. 239
OK. 240
So we can do that even though there is no break statement and on what we will do is to control our. 241
So that's about it. 242
And let me just run this one more time resume. 243
So we are done. 244
Now here are the big points if you want remore all the brick ones at once. 245
You can click this icon here remore all break points. 246
So it says are are you sure. 247
Yes. 248
Now if you want to remove this you can also do directory more or terminated branches so there is one 249
more from some other session. 250
So let's just close this so you can have multiple debug sessions. 251
OK. 252
So that's about it. 253
I think those are all important things that we need to know about about debugging. 254
And we have blown that. 255
So what we learned is all the fundamental stuff now in the supplementary notes I will include a pointer 256
to a really good read you'll see it is that coward's debugging debugger at a very deep level. 257
Those rules are specific to debugging are not instructed by a person called Mark Baxter and it's really 258
good stuff. 259
OK so if you want to go into more details you have to do it you can look at those videos it's over one 260
hour long. 261
But what be covered here is definitely the basic stuff fundamental stuff and it should be more than 262
enough but you can also go and look check all those videos. 263
Not that debuggers are also used on Glan side to debug issues in Javascript. 264
So it's not just Java code. 265
You can also have a debugger or in the client side. 266
So Wondolowski a debugger I use extensively is cardless firebug. 267
And it can be installed in the browser and it works pretty much like Eclipse's a debugger. 268
In fact I think most debuggers would work in a similar way. 269
So that's about it. 270
And I hope you enjoyed it.