1
00:00:00,240 --> 00:00:05,520
Arrays can store many values at once, but a variable does not store the array, it stores a reference

2
00:00:05,520 --> 00:00:06,540
that points to it.

3
00:00:07,020 --> 00:00:11,610
This can introduce a lot of bugs, so it helps to visualize the runtime using breakpoints.

4
00:00:12,660 --> 00:00:15,630
In this lesson, you're going to learn to debuggers using breakpoints.

5
00:00:17,730 --> 00:00:21,750
All right, at this point in the course, you're well aware of the reference trap, but it would be

6
00:00:21,750 --> 00:00:24,270
nice to visualize the reference dropped during runtime.

7
00:00:24,780 --> 00:00:26,160
So open this file.

8
00:00:27,470 --> 00:00:29,690
Place breakpoints next to each line of code.

9
00:00:39,760 --> 00:00:44,290
And you know what, I'm actually going to remove the breakpoints from functions and Lupe's.

10
00:00:47,020 --> 00:00:48,670
All right, then launched the debugger.

11
00:00:56,900 --> 00:01:01,730
The verbal greeting stories I reference that points to an array with two string values.

12
00:01:08,190 --> 00:01:13,020
And by setting farewell equal to greeting farewell copies, that same reference.

13
00:01:16,820 --> 00:01:20,630
Farewell and greeting cherie reference that points to the same array.

14
00:01:24,140 --> 00:01:27,380
And so updating the array through farewell effects, greeting.

15
00:01:30,480 --> 00:01:34,980
And now it's really nice that you can finally see the reference drop in real time, and this is why

16
00:01:34,980 --> 00:01:41,160
I love this code anyways, this is considered a bug because the application doesn't behave like we expect

17
00:01:41,160 --> 00:01:45,770
it to, because if we keep stepping into the runtime, that's exactly what happens.

18
00:01:53,590 --> 00:01:57,460
And the solution, obviously, is to farewell equal to a copy of the Iraq.

19
00:02:14,860 --> 00:02:16,330
Launch another debugging session.

20
00:02:23,160 --> 00:02:27,750
The verbal greeting saw as a reference that points to an array with two string values.

21
00:02:31,310 --> 00:02:37,250
Farewell was a reference that points to a copy of the original array, and so both variables are completely

22
00:02:37,250 --> 00:02:38,480
independent of each other.

23
00:02:48,980 --> 00:02:53,560
All right, now, debugging a one dimensional array is easy to erase are a different story.

24
00:02:54,260 --> 00:03:00,410
So open up upper triangular java and the goal is to produce an upper triangular matrix from the two

25
00:03:00,410 --> 00:03:00,890
Deira.

26
00:03:02,060 --> 00:03:06,680
An upper triangular matrix is a two tier with zeros below the main diagonal.

27
00:03:12,440 --> 00:03:13,790
If you're on the current code.

28
00:03:19,330 --> 00:03:20,320
It's going to crash.

29
00:03:21,440 --> 00:03:26,330
First step is to find out why something is wrong and using breakpoints, we can visualize the runtime

30
00:03:26,330 --> 00:03:27,280
and figure it out.

31
00:03:34,820 --> 00:03:36,760
Then launch a new debugging session.

32
00:03:45,500 --> 00:03:51,980
And woops, it seems that every time the inner loop runs or increasing the outer loop counter, eventually

33
00:03:51,980 --> 00:03:55,190
the outer loop counter exceeds the bounds of the array and crashes the up.

34
00:03:55,400 --> 00:03:58,670
This mistake is so common and it can happen when you're not paying attention.

35
00:03:58,910 --> 00:04:02,270
But seeing that runtime helps us debug the problem and see it right away.

36
00:04:03,840 --> 00:04:04,950
All right, we run the code.

37
00:04:11,100 --> 00:04:13,950
The nested loop sets every element to zero, that's not good.

38
00:04:15,270 --> 00:04:19,420
If you look back at the output, only elements below the main diagonal should be zero.

39
00:04:20,190 --> 00:04:23,010
Now it's hard to keep track of two counters at the same time.

40
00:04:23,430 --> 00:04:26,970
And so this makes it hard to predict how we're going to use them to achieve our goal.

41
00:04:27,360 --> 00:04:30,450
But it helps to launch a debugging session to visualize the runtime.

42
00:04:30,600 --> 00:04:32,340
Hopefully then we can see a pattern.

43
00:04:36,540 --> 00:04:41,430
And you know what, after visualizing the array without even stepping into the nested loop, the pattern

44
00:04:41,430 --> 00:04:41,940
is clear.

45
00:04:42,600 --> 00:04:47,430
The elements that need to be zero have a J index lower than the index.

46
00:04:53,700 --> 00:04:55,710
So if Jay is smaller than I.

47
00:05:01,150 --> 00:05:04,240
Then we're going to say matrix age is equal to zero.

48
00:05:15,940 --> 00:05:19,000
All right, launch another debugging session to visualize the runtime.

49
00:05:36,330 --> 00:05:39,660
And therein lies the beauty of visual analysis.

50
00:05:40,140 --> 00:05:44,250
It helps to have a clear visual of what's going on instead of just looking at code.

51
00:05:51,250 --> 00:05:53,470
And there's your upper triangular matrix.

52
00:05:56,610 --> 00:06:02,310
In this lesson, you learn to debug using breakpoints now debugging in normal arrays, easy, but the

53
00:06:02,310 --> 00:06:04,740
usage of a tutera implies a nested loop.

54
00:06:04,740 --> 00:06:08,630
And so it's hard to keep track of the counters Ingi and how they're affecting your array.

55
00:06:08,940 --> 00:06:14,580
But when you can visualize the runtime step by step, you can easily see how the state of the tiaro

56
00:06:14,580 --> 00:06:15,560
is going to change.

