Eclipse and Java – Using the Debugger – Lesson 2
Video Title: Eclipse and Java – Using the Debugger – Lesson 2
Hello welcome back to using the debugger in the last lesson we learned how to start a debug session and we introduced the three basic step commands step over step into and step return in this lesson we’re going to learn a little more about navigating within the debugger and then
We’re going to learn how to examine the contents of variables inside the program to get started we’ll select the my library class and then we’ll select run debug as java application and just like in the last lesson this is going to take us to our breakpoint at 1:58 stop at the
First line after that which is 160 and we’re inside the debug perspective at this point we need to introduce a small complication will step over line 160 and go to line 161 where we call the book constructor book b1 equals new book war and peace’ and this time we’ll step into
The book constructor step into line 161 and let’s see what happens now we might have expected to go into the first line of the book constructor but instead we’ve got all of these new stack frames that were put on top of our line 161 now what happened since the book class is a
Separate class from our current my library class the Java Runtime engine has to do some work behind the scenes to load the book class and that’s what we’re seeing in all of these stack frames now if we press step return a few times we’ll start pressing it here we
Can see that the stack frames are slowly being removed and when we press it the last time we get back to our one stack frame line 161 now if we step in again we do what we expected to do the first time which is to open the constructor for the book
Class now let’s step return to get out of this constructor and let’s step over twice to get down to line 163 and now let’s try the step-in two again this time it takes us right into the book constructor this is because the JRE already has the book class ready to use
So it doesn’t need to repeat the behind-the-scenes work it did the first time we needed to load the book class now most of the time when we are using the debugger we’re looking for problems in our own code not in the Java language classes or some third party library so
We would like to have the debugger step through this part of the program without stopping fortunately it’s easy to set this up first we’ll right click up in the debug window and select edit step filters next we’ll select this box use step filters and then we’ll select the
Box that says Java dot asterisks which will filter out any packages starting with the word Java and now we’ll press ok notice that the button called use step filters is now toggled on this is a toggle button we can toggle off and on we want to make sure it’s toggled on now
Now let’s try this by stepping over to get to line 166 so we’ll press step return to get out of the constructor will step over twice to get down to line 166 and now we’re going to open the person constructor which is a class we haven’t accessed yet so now if we step
Into the person constructor we go right into where we expect which the constructor and we skip all of those other stack frames so the filter is doing what we want it to do next let’s talk a little more about the three basic step commands it’s important to understand that the step into command
Only steps into a method if there is a method or constructor on the given line of code otherwise it does the same thing as the step over for example here there’s no method to step into so if we press step into it operates the same as
Step over so step over goes down and step into it also go down to the next line similarly if we’re at the last line of a method and about to return to the calling method or here we’re at the last line of the constructor about to return
To the main method any of the three buttons will take us back whether it’s a step return a step over or the step into so for example again step into does the same thing as step over and takes us back to the calling method also you can
Use f5 for step into f6 for step over and f7 for step return you’d rather use a function key next let’s look at two ways to quickly skip to a specific line of code the first is to set another breakpoint let’s stop and restart a new debugging
Session we can just press the debug button up there now here we are at line 160 again let’s say we wanted to go right to line 166 well one way to do that would be to go down to line 166 double-click to set a breakpoint and then just press the
Resume resume button takes us either to the end of the program or to the next breakpoint now another way to do this without setting a breakpoint is to use the run two line command let’s say we wanted to go down to line 171 we can go down click on line 171
Wickett we could either right-click or we can use run go run to line which is also got a control our shortcut and again it runs down to the selected line in this case line 171 without the need of setting a breakpoint so at this point you should be getting more comfortable
Running in debug mode setting breakpoints and stepping through the code now we’re ready to look at the other side of debugging how to examine the value of the programs variables let’s restart our session and go to line 166 again so we’ll hit terminate debug my library since we have a breakpoint we
Can just press resume to go line 166 and then let’s press step into at this point in the program we’re just about to enter the person constructor which has been called from the my library main method we have two stack frames the top one for the person constructor the lower one for
The line in main where we called the constructor now you can think of stack frames as being like a stack of paper on your desk whenever we call a method a new piece of paper is added to the top of the stack when a method returns to
The calling program the top piece of paper is removed from the stack the top frame in the stack always points to where we are in the program right now every time we call a method or constructor you can think of it as going down one level in the program when this
Happens a new stack frame is added to the top of the stack when we return from a method or constructor we come back up with level and the frame for that method or constructor is removed from the stack now each stack frame also provides a context for variables in other words at
Any point in the program certain variables are defined or are and scope these are shown in the variables view in the upper right portion of the screen for example in the person constructor we have the variable this which refers to the current person object if we expand we see that at
Present this is defined with default values maximum books 0 and name of null this is because the constructor hasn’t run yet now a really cool thing about debugging is that you can see the program work right before your eyes let’s press the step over now we’re
Ready to run line 25 in the person class will press step over one more time and we can see that name now has changed from null to unknown name and it’s highlighted in yellow indicating that it’s just changed if we press step over one more time now we can see maximum
Books has gone from 0 to 3 and again it’s highlighted at this point we’re ready to leave the person constructor if we press step over one more time and of course since we’re ready to leave we could actually press any of the step buttons notice that our person stack frame
Disappears and we’re back to the my library main method line 166 now this is a little tricky at this point line 166 is partially executed we’ve created the new person on the right hand side but we haven’t yet assigned that to the variable Jim now how do we know this
Well there are a couple different ways first if we look up at the variables view we don’t see an entry for Jim this tells us that Jim hasn’t been defined yet second we can use the inspect command to look at any expression and see what its current value is let’s try it
We’ll highlight new person will right-click and say inspect and here we see the same object we saw when we were looking at the person constructor now let’s try the same thing with Jim we’ll highlight right-click inspect and it says Jim cannot be resolved so Jim hasn’t been
Created yet now let’s press step over one more time and now we see that Jim has been added to the variables list up here and we can expand and see the values we expect and now if we highlight and we can use control shift I to inspect it’s a shortcut we see that
Again Jim has been defined with unknown name and maximum books 3 now let’s step into line 167 which takes us into the setname method of the person class notice that the variables view now has changed and shows the fields for this person and also shows a local variable
New name which is set to Jim let’s go to the debug view and select the lower stack frame the variables view changes back to the variables that are in scope as of line 167 of the main method also the Java editor view goes back to the
Line in main where we called set name and we can see it’s got a little bit lighter highlight than the currently active view so we can use the stack frames to see the variables that are in scope as of the point in the program corresponding to each stack frame let’s
Step return to the main method and look more closely at the variables view let’s select the test library very ample notice that we get a display in the lower portion of the view called the detail pane this is the two string output of the selected variable if we
Switch to b1 we see the two string a b1 which shows the title the author and whether or not it’s available and the two string of the test library shows us the name of the library and how many books and how many people are in it now
There’s a menu for the variables view we accessed by the menu icon and there’s two sub menus layout which gives us options for how to display the view and whether to use columns or not and then the Java sub menu gives us some options for what types of Java members to
Display and how to display those at this point we’ve learned a lot about stepping through a program in debug mode and we’ve seen how to view the contents of variables in the next lesson we’ll learn more about looking inside the running program then we’ll apply what we’ve learned and actually start debugging our
My library project this is the end of lesson two I marked extra saying so long for now you
-
Sale!
Wireless WIFI Repeater Extender Amplifier Booster 300Mbps
$29.99$14.99 Add to cartWireless WIFI Repeater Extender Amplifier Booster 300Mbps
Categories: Electronics, Wi-Fi Router, Wireless Wi-Fi Extender Tags: 300Mbps, 802.11N, Amplifier, Booster, Extender, mobile wi-fi booster, Remote, WIFI, Wireless, Wireless WIFI, Wireless WIFI Repeater, Wireless WIFI Repeater Extender, Wireless WIFI Repeater Extender Amplifier, Wireless WIFI Repeater Extender Amplifier Booster, Wireless WIFI Repeater Extender Amplifier Booster 300Mbps$29.99$14.99 -
Sale!
Full RGB Light Design Gaming Headset Headphones with Mic
$24.99$14.99 Add to cartFull RGB Light Design Gaming Headset Headphones with Mic
Categories: Electronics, Gaming, Gaming Headsets Tags: Design, Full, Full RGB Light Design Gaming Headset, Full RGB Light Design Gaming Headset Headphones, Full RGB Light Design Gaming Headset Headphones with Mic, Gamer, Gaming, Gaming Headset Headphones, gaming headset wireless, Headphone, Headphones, Headset, Light, Mic, Package, RGB$24.99$14.99 -
Sale!
Wireless BlueTooth Multi-Device Keyboard Mouse Combo
$39.99$19.99 Add to cartWireless BlueTooth Multi-Device Keyboard Mouse Combo
Categories: Electronics, Gaming, Gaming Keyboards, Keyboard Mouse Combos Tags: Combo, Keyboard, keyboard mouse combos, Mouse, MultiDevice, Set, WireKeyboard Mouse Combo, Wireless, Wireless BlueTooth Keyboard Mouse Combo, Wireless BlueTooth Keyboard Mouse Combos, Wireless BlueTooth Multi-Device Keyboard Mouse Combo, Wireless BlueTooth Multi-Device Keyboard Mouse Combos$39.99$19.99 -
Sale!
High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
$199.99$139.99 Add to cartHigh Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
Categories: Gaming, Gaming Chairs Tags: Adjustable, Chair, computer chairs, Desk, Executive, Gaming, Girl, Headrest, High, High Back Leather Executive Adjustable Swivel Gaming Chair, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar, High Back Leather Executive Adjustable Swivel Gaming Chairs, Leather, Lumbar, Office, Racing, Swivel$199.99$139.99 -
Sale!
Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
$29.99$19.99 Select optionsProfessional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
SKU: N/A Categories: Electronics, Gaming, Gaming Headsets Tags: Cancelling, Gaming, Gaming Headphones with Noise Cancelling Microphone, gaming headset, Headphones, Headset, LED, Light, Mic, Microphone, Noise, Professional, Professional LED Light Wired Gaming Headphones, Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone, Wired, Wired Gaming Headphones, Wired Gaming Headphones with Noise Cancelling Microphone$29.99$19.99 -
Sale!
Gaming Desk with LED Lights USB Power Outlets and Charging Ports
$349.99$249.99 Select optionsGaming Desk with LED Lights USB Power Outlets and Charging Ports
SKU: N/A Categories: Computer Desk, Gaming, Gaming Desk Tags: and Charging Ports, Charging, Desk, Desks, Gaming, gaming desk with led lights, Gaming Desks with LED Lights, Home, LED, Lights, Monitor, Office, Outlets, Port, Power, Room, Stand, USB, USB Power Outlets, White, Workstation$349.99$249.99 -
Sale!
Wired Mixed Backlit Anti-Ghosting Gaming Keyboard
$99.99$79.99 Add to cartWired Mixed Backlit Anti-Ghosting Gaming Keyboard
Categories: Electronics, Gaming, Gaming Keyboards Tags: Antighosting, Backlit, Blue, brown, Gaming, Gaming Keyboard, gaming keyboards, gaming keyboards and mouse, Keyboard, Laptop, Switch, Wired, Wired Mixed Backlit Anti-Ghosting Gaming Keyboard, Wired Mixed Backlit Anti-Ghosting Gaming Keyboards, Wired Mixed Backlit Gaming Keyboard$99.99$79.99 -
Sale!
Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
$119.99$59.99 Add to cartWireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
Categories: Electronics, Gaming, Gaming Headsets Tags: 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, ANC, Audio, Bluetooth, Cancellation, Ear, Earphone, gaming headset, Headphones, Headset, Hi-Res Over the Ear Headphones Headset, HiRes, Noise, Wireless, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Headphones, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headsets$119.99$59.99 -
Sale!
Wired Sports Gaming Headset Earbuds with Microphone
$19.99$9.99 Select optionsWired Sports Gaming Headset Earbuds with Microphone
SKU: N/A Categories: Gaming, Gaming Headsets Tags: Accessories, Earbud, Earphone, Earphones, Gaming, gaming headset with microphone, Headphones, Headset, IOS, Microphone, Sports, Wired, Wired Sports Gaming Headset Earbuds, Wired Sports Gaming Headset Earbuds with Microphone, Wired Sports Headset Earbuds$19.99$9.99 -
Sale!
150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
$49.99$29.99 Add to cart150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
Categories: Charging Stations, Electronics Tags: 150W, 150W Charging Station, 150W Universal Multi USB Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Stations, 150W Universal Multi USB MAX Charging Station, 16 Port MAX Charging Station, 3.5A, Charger, Charging, Fast, laptop charging stations, Max, Multi, Port, Stand, Station, Universal, USB$49.99$29.99
Thank you so much for making these videos.
http://eclipsetutorial.sourceforge.net/debugger.html
where is the source code??
Listen I get its made in 2007 but jesus why is the mpeg compression so bad? I mean holy shit, some the artifacting is so bad there's just a giant half-speech bubble just floating at around 3:27.
11:20
Wow! Been coding for so long and never had to deal with not wanting to step through Java code until using the latest greatest Eclipse tool. Eclipse has so many whistles that by default you have to use the debug filters to step through code. Allowing to step through Java code should be a given and not an option to add it to your tons of filtering options in Eclipse? You need an entire Encyclopedia to just use Eclipse, what happen to simplicity of using an IDE???
Superb
Perfect Tutorial- All in one(Slow ,effective,Simple ,well explained etc ……)
Thanks a lot.
everything is fine just the quality of the film is very low 🙁