1 00:00:00,390 --> 00:00:01,410 ‫Welcome back. 2 00:00:01,440 --> 00:00:06,750 ‫In this video, we are going to check out autos and locals and also breakpoints a little more. 3 00:00:06,750 --> 00:00:12,900 ‫So we saw how to use breakpoints in the last video and we created this one breakpoint at the point where 4 00:00:12,900 --> 00:00:19,350 ‫we create this local list or this local variable called friends, which is only available in our main 5 00:00:19,350 --> 00:00:19,830 ‫method. 6 00:00:19,830 --> 00:00:25,110 ‫And then we can, of course, go ahead and create some more of those breakpoints. 7 00:00:25,110 --> 00:00:27,720 ‫So I'm just going to create two breakpoints. 8 00:00:27,720 --> 00:00:31,080 ‫Now, let's say we want to have a look at our breakpoints. 9 00:00:31,260 --> 00:00:36,390 ‫And in this example, it's super easy because we only have those two breakpoints, right? 10 00:00:36,390 --> 00:00:38,370 ‫So they are visible all the time. 11 00:00:38,370 --> 00:00:40,230 ‫But now imagine we did this. 12 00:00:40,230 --> 00:00:42,810 ‫So we have summed it up. 13 00:00:42,810 --> 00:00:46,470 ‫We really just want to break it down on the higher level. 14 00:00:46,470 --> 00:00:48,210 ‫And now we only see this one breakpoint. 15 00:00:48,210 --> 00:00:50,060 ‫But where are all the other breakpoints? 16 00:00:50,070 --> 00:00:53,160 ‫Well, what you can do is you can start. 17 00:00:54,080 --> 00:00:56,740 ‫And then or start debugging by pressing a five. 18 00:00:56,750 --> 00:01:01,880 ‫And then the other thing that you can do is you can check out your breakpoints. 19 00:01:01,880 --> 00:01:09,710 ‫So control alt b is the shortcut or you can just go to Windows breakpoints here from debug debug Windows 20 00:01:09,710 --> 00:01:10,310 ‫breakpoints. 21 00:01:10,310 --> 00:01:15,790 ‫And that will open up this little tab here, which shows you the different breakpoints that you have. 22 00:01:15,800 --> 00:01:23,210 ‫So we have a breakpoint in program, CSS line ten, character 13 and another one in program CSS line 23 00:01:23,210 --> 00:01:24,900 ‫21 for character 13. 24 00:01:24,920 --> 00:01:25,250 ‫All right. 25 00:01:25,250 --> 00:01:28,130 ‫So these are the two breakpoints that we have. 26 00:01:28,130 --> 00:01:32,990 ‫And now in order to get rid of a breakpoint, what we can do is, of course, we can press on the breakpoint. 27 00:01:32,990 --> 00:01:35,270 ‫So here on the left hand side, we can click on it. 28 00:01:35,270 --> 00:01:38,980 ‫And as you can see, it completely disappears from our breakpoints. 29 00:01:38,990 --> 00:01:43,010 ‫Once we do that, we can also just deactivated breakpoint. 30 00:01:43,010 --> 00:01:45,680 ‫Now you can see it's white in the middle. 31 00:01:45,680 --> 00:01:48,120 ‫So let me do that with this breakpoint here. 32 00:01:48,130 --> 00:01:49,160 ‫You can see it better. 33 00:01:49,250 --> 00:01:51,260 ‫You can see now it's not fully red anymore. 34 00:01:51,260 --> 00:01:52,640 ‫It's not filled with red anymore. 35 00:01:52,640 --> 00:01:53,960 ‫It's filled with white. 36 00:01:53,960 --> 00:01:54,290 ‫All right. 37 00:01:54,290 --> 00:01:56,570 ‫So it's still there, but it's deactivated. 38 00:01:56,570 --> 00:02:00,980 ‫So you can deactivate breakpoints any time with this window. 39 00:02:00,980 --> 00:02:02,690 ‫With this breakpoint window. 40 00:02:02,870 --> 00:02:03,290 ‫All right. 41 00:02:03,290 --> 00:02:07,850 ‫So this might not be useful in our specific case here because it's a super short program. 42 00:02:07,850 --> 00:02:08,060 ‫Right. 43 00:02:08,060 --> 00:02:10,340 ‫We don't have too much going on here. 44 00:02:10,340 --> 00:02:16,220 ‫But once you have a program where you have breakpoints in many different files, this comes in handy 45 00:02:16,220 --> 00:02:18,500 ‫and it really helps you out there. 46 00:02:18,740 --> 00:02:19,160 ‫All right. 47 00:02:19,160 --> 00:02:23,630 ‫So the next thing that I would like to show you, and that's a very important one, especially to figure 48 00:02:23,630 --> 00:02:29,540 ‫out where your bugs lie and that's to use locals and orders. 49 00:02:29,720 --> 00:02:30,050 ‫All right. 50 00:02:30,050 --> 00:02:31,340 ‫Let's start with orders. 51 00:02:31,910 --> 00:02:35,000 ‫You can see we have this new window here called orders. 52 00:02:35,090 --> 00:02:43,160 ‫Orders will automatically show us the variables which are around the current breakpoint so the ones 53 00:02:43,160 --> 00:02:44,570 ‫that are relevant currently. 54 00:02:44,690 --> 00:02:49,370 ‫So there's this args variable, which is this one here at the top from our main method. 55 00:02:49,370 --> 00:02:54,320 ‫So this args variable and then we have this friend's variable which currently is null. 56 00:02:54,320 --> 00:02:58,580 ‫And once we go to the next step, so we step over. 57 00:03:00,230 --> 00:03:01,700 ‫We can see that now. 58 00:03:01,850 --> 00:03:03,920 ‫We have friends and party friends. 59 00:03:03,920 --> 00:03:09,440 ‫So all those shows us automatically the variables that are surrounding the breakpoint that are close 60 00:03:09,440 --> 00:03:10,790 ‫to where we are currently. 61 00:03:10,850 --> 00:03:11,240 ‫All right. 62 00:03:11,240 --> 00:03:15,710 ‫So here I'm with friends and you can see that we have seven entries there. 63 00:03:15,710 --> 00:03:18,440 ‫And then we have party friends, which is at this point null. 64 00:03:18,440 --> 00:03:23,180 ‫But once we step over, we can see now party friends is what is looked at. 65 00:03:23,180 --> 00:03:23,570 ‫All right. 66 00:03:23,570 --> 00:03:30,630 ‫So we have this variable count and we have this variable party friends, which has some additional information. 67 00:03:30,630 --> 00:03:33,440 ‫You can see the count of party friends is zero at this point. 68 00:03:33,440 --> 00:03:37,850 ‫You can see the type here if you want to know more about it, it's a system collection list. 69 00:03:37,850 --> 00:03:41,960 ‫And then we have this party friends count, which is also zero. 70 00:03:42,110 --> 00:03:42,530 ‫All right. 71 00:03:42,530 --> 00:03:46,100 ‫So Count, which is this one here and this one over here. 72 00:03:46,190 --> 00:03:50,840 ‫And then we have party friends, which has a count of zero. 73 00:03:51,260 --> 00:03:51,740 ‫All right. 74 00:03:51,740 --> 00:03:55,130 ‫So that's the general idea or actually party friends. 75 00:03:55,130 --> 00:03:56,180 ‫And then we have count. 76 00:03:56,180 --> 00:03:57,290 ‫So it's two different things. 77 00:03:57,290 --> 00:04:01,760 ‫As you can see, there is the party friends count, which is the amount of party friends and there is 78 00:04:01,760 --> 00:04:06,650 ‫the party friends list, which is the list which currently doesn't have any friends in there or any 79 00:04:06,680 --> 00:04:07,640 ‫entries in there. 80 00:04:07,910 --> 00:04:08,240 ‫All right. 81 00:04:08,240 --> 00:04:10,040 ‫So that's our autos. 82 00:04:10,040 --> 00:04:14,690 ‫And it's super handy when you are looking at variables that you currently have right now. 83 00:04:15,020 --> 00:04:20,000 ‫Now, what you also can do is you can modify those. 84 00:04:20,000 --> 00:04:20,300 ‫All right. 85 00:04:20,300 --> 00:04:22,010 ‫So you could modify the value here. 86 00:04:22,010 --> 00:04:28,250 ‫You could go ahead and enter five and test how your program behaves once you change the value to a different 87 00:04:28,250 --> 00:04:28,700 ‫value. 88 00:04:28,730 --> 00:04:32,930 ‫As you can see, I've changed it to five and now I could see, okay, how would my program behave once 89 00:04:32,930 --> 00:04:37,070 ‫I add a or enter a value of five, for example? 90 00:04:37,430 --> 00:04:37,880 ‫All right. 91 00:04:37,880 --> 00:04:39,180 ‫So that's one thing. 92 00:04:39,200 --> 00:04:43,370 ‫The other one that I would like to show you are locals. 93 00:04:43,370 --> 00:04:46,610 ‫But before we do that, I would like to show you the watch first. 94 00:04:46,610 --> 00:04:50,900 ‫So let's go to the watch and watch opens up this. 95 00:04:51,680 --> 00:04:54,150 ‫One note, which looks similar to what we have just seen. 96 00:04:54,170 --> 00:04:58,980 ‫And now you can add items to watch, by the way, at the bottom. 97 00:04:59,000 --> 00:05:02,810 ‫Autos is still there, so it's just a new tab here at the very bottom. 98 00:05:02,810 --> 00:05:04,540 ‫And here is watch one. 99 00:05:04,550 --> 00:05:09,320 ‫That's because, well, breakpoints has taken some space and it's important. 100 00:05:09,320 --> 00:05:16,340 ‫But what we can do is we can at any point we can drag out all those and have it at the side here so 101 00:05:16,340 --> 00:05:17,660 ‫we could compare them. 102 00:05:17,660 --> 00:05:25,160 ‫So let's say I want to add my friends, so I'm just going to add party friends to my list. 103 00:05:25,790 --> 00:05:26,270 ‫All right. 104 00:05:26,270 --> 00:05:30,590 ‫Party friends entered and you can see the party friends count is zero. 105 00:05:30,710 --> 00:05:33,890 ‫Then it's always important to where you are right now. 106 00:05:33,890 --> 00:05:44,030 ‫So at this point, I'm over here, so I'm just going to look at Current Friend and let me enter. 107 00:05:44,030 --> 00:05:45,590 ‫As you can see, I'm getting an error name. 108 00:05:45,590 --> 00:05:50,960 ‫Current Friend does not exist in the current context, so it doesn't exist at that point yet, but it 109 00:05:50,960 --> 00:05:52,250 ‫will exist later on. 110 00:05:52,250 --> 00:05:58,700 ‫So let's also look at friends because friends is also something that doesn't exist in the current context. 111 00:05:58,820 --> 00:05:59,720 ‫Why is that? 112 00:05:59,720 --> 00:06:04,940 ‫Well, because right now, as you can see, the arrow is within my get party friends. 113 00:06:04,940 --> 00:06:07,340 ‫So we're within this method. 114 00:06:07,370 --> 00:06:14,780 ‫Now, the scope of our whole variables is within this method and this friend's variable and this party 115 00:06:14,780 --> 00:06:15,800 ‫friend's variable. 116 00:06:15,890 --> 00:06:18,440 ‫They are not available in here. 117 00:06:18,440 --> 00:06:21,260 ‫So this is not the party friends that we're looking at here. 118 00:06:21,260 --> 00:06:21,890 ‫All right. 119 00:06:21,890 --> 00:06:24,950 ‫Because the party friends that we're looking at is this one here. 120 00:06:25,220 --> 00:06:25,940 ‫Why is that? 121 00:06:25,940 --> 00:06:27,740 ‫Well, it's because of scope. 122 00:06:27,740 --> 00:06:28,030 ‫All right. 123 00:06:28,040 --> 00:06:33,740 ‫Scope is a very important concept, because a variable that is created within a method is only available 124 00:06:33,740 --> 00:06:34,880 ‫within that method. 125 00:06:35,090 --> 00:06:42,590 ‫That's why we can't use friends or party friends from our main method within our get party friends, 126 00:06:42,590 --> 00:06:44,450 ‫because it's a different method, right? 127 00:06:44,450 --> 00:06:45,950 ‫If we created them globally. 128 00:06:45,950 --> 00:06:51,590 ‫So if we created them here at the top as fields for our class, then they would be available in all 129 00:06:51,590 --> 00:06:52,580 ‫of the methods. 130 00:06:52,820 --> 00:06:53,180 ‫All right. 131 00:06:53,180 --> 00:06:54,650 ‫So that's really important here. 132 00:06:54,650 --> 00:06:57,170 ‫I looked at into scope in another video, I think. 133 00:06:57,170 --> 00:07:03,890 ‫But here it's really, again, very easy to see because, well, we can directly see the values that 134 00:07:03,890 --> 00:07:04,550 ‫we get. 135 00:07:05,060 --> 00:07:05,390 ‫All right. 136 00:07:05,390 --> 00:07:08,840 ‫Now, let's go ahead with the program and let's just. 137 00:07:10,120 --> 00:07:10,850 ‫Continue. 138 00:07:10,870 --> 00:07:12,350 ‫Let's just say, okay, let's continue. 139 00:07:12,420 --> 00:07:18,520 ‫You can see now party friends and current friends are available because now current friend is null. 140 00:07:18,520 --> 00:07:23,940 ‫So we can just go to the next step and we can see that the current friend is Michele. 141 00:07:23,950 --> 00:07:32,320 ‫So our program gives us those values and at the same time at the right hand side, all those constantly 142 00:07:32,350 --> 00:07:37,750 ‫gives us the closest values, values that are closest to the breakpoint that we are at right now. 143 00:07:38,080 --> 00:07:38,530 ‫All right. 144 00:07:38,530 --> 00:07:42,280 ‫So once I jump out and I jump out again. 145 00:07:46,070 --> 00:07:49,430 ‫And then I see I'm at friends, so I had to jump up multiple times. 146 00:07:49,430 --> 00:07:54,890 ‫But now I'm in the main method again because I jumped out of my get party friends and now party Frances. 147 00:07:54,890 --> 00:08:04,880 ‫Now my current friend is Carlos and my friends is the count of two, so I only have two friends in my 148 00:08:04,880 --> 00:08:05,480 ‫list. 149 00:08:05,870 --> 00:08:09,740 ‫Now that's a weird one because I thought I had seven friends in my list. 150 00:08:10,010 --> 00:08:15,230 ‫Well, that's something that we have to look into in a little more depth, because what we're doing 151 00:08:15,230 --> 00:08:23,030 ‫is a huge mistake and it's a very beginner kind of mistake we are removing from a list now we're passing 152 00:08:23,030 --> 00:08:28,700 ‫by reference, we're not passing by value, and that's something that we will look into in the next 153 00:08:28,700 --> 00:08:32,720 ‫video just as a little preparation for you. 154 00:08:32,720 --> 00:08:37,790 ‫So and then before we do so, I would like to check out another window. 155 00:08:37,790 --> 00:08:39,500 ‫And as you can see, there are plenty of windows. 156 00:08:39,500 --> 00:08:42,440 ‫So you can learn so much about debugging. 157 00:08:42,440 --> 00:08:48,440 ‫If you just check out the different windows and see where your program is at every single line and what 158 00:08:48,440 --> 00:08:49,220 ‫the state is. 159 00:08:49,370 --> 00:08:51,890 ‫And you can also check out the memory and so forth. 160 00:08:51,890 --> 00:08:55,550 ‫But what's important for now is the locals. 161 00:08:55,550 --> 00:08:57,560 ‫So I would like to show you locals. 162 00:08:57,710 --> 00:09:05,750 ‫Locals shows you the variables that are available in the local context so in the scope that we're currently 163 00:09:05,750 --> 00:09:06,470 ‫looking at. 164 00:09:06,470 --> 00:09:10,940 ‫So as I just said, the scope is the method that we're in. 165 00:09:10,940 --> 00:09:12,770 ‫So let's start it again. 166 00:09:13,250 --> 00:09:14,570 ‫Let's start debugging. 167 00:09:14,570 --> 00:09:21,950 ‫And by the way, you could once it's debugging, you can also restart debugging by pressing this button 168 00:09:21,950 --> 00:09:25,580 ‫over here, the restart button or by pressing control shift. 169 00:09:25,580 --> 00:09:30,440 ‫F five So in the current context, that's the local window where it's important. 170 00:09:30,440 --> 00:09:32,570 ‫We're currently at locals, not at Otto's. 171 00:09:32,810 --> 00:09:34,400 ‫We're currently looking at locals. 172 00:09:34,400 --> 00:09:40,580 ‫So we have arcs, which is this main arcs, the string out here, this string list or array. 173 00:09:40,580 --> 00:09:44,270 ‫And then we have our friends and we have our party friends. 174 00:09:44,270 --> 00:09:50,120 ‫So these are the variables that are available within this main method, and that's why we are currently 175 00:09:50,240 --> 00:09:52,160 ‫being displayed, those two values. 176 00:09:52,160 --> 00:09:57,830 ‫So we can step over, we can see, okay, we have seven friends, we can look at our party friends, 177 00:09:57,830 --> 00:10:04,280 ‫we can see a count is zero, but the count variable itself is four and we have list. 178 00:10:04,280 --> 00:10:07,850 ‫So now we're not looking at friends anymore, but we're looking at the list. 179 00:10:07,850 --> 00:10:08,570 ‫So what is list? 180 00:10:08,570 --> 00:10:10,940 ‫Well, list is this variable that was passed to us. 181 00:10:11,870 --> 00:10:16,400 ‫So you can see here this list was passed to us and this list has a count of seven. 182 00:10:17,310 --> 00:10:17,730 ‫All right. 183 00:10:17,730 --> 00:10:18,650 ‫And what's in there? 184 00:10:18,660 --> 00:10:20,880 ‫Well, there are all of the different names that we have. 185 00:10:21,210 --> 00:10:21,570 ‫All right. 186 00:10:21,570 --> 00:10:24,690 ‫So that was locals, autos and breakpoints. 187 00:10:25,020 --> 00:10:30,600 ‫And in the next video, we are going to fix our back because we still have our bug in here because we're 188 00:10:30,870 --> 00:10:33,510 ‫checking for the wrong value. 189 00:10:33,540 --> 00:10:39,360 ‫But at the same time, we're going to see how to fix some other problems that we have in our program. 190 00:10:39,510 --> 00:10:39,930 ‫All right. 191 00:10:39,930 --> 00:10:41,670 ‫So see you in the next video.