Arrays can store many values at once, but a variable does not store the array, it stores a reference
that points to it.
This can introduce a lot of bugs, so it helps to visualize the runtime using breakpoints.
In this lesson, you're going to learn to debuggers using breakpoints.
All right, at this point in the course, you're well aware of the reference trap, but it would be
nice to visualize the reference dropped during runtime.
So open this file.
Place breakpoints next to each line of code.
And you know what, I'm actually going to remove the breakpoints from functions and Lupe's.
All right, then launched the debugger.
The verbal greeting stories I reference that points to an array with two string values.
And by setting farewell equal to greeting farewell copies, that same reference.
Farewell and greeting cherie reference that points to the same array.
And so updating the array through farewell effects, greeting.
And now it's really nice that you can finally see the reference drop in real time, and this is why
I love this code anyways, this is considered a bug because the application doesn't behave like we expect
it to, because if we keep stepping into the runtime, that's exactly what happens.
And the solution, obviously, is to farewell equal to a copy of the Iraq.
Launch another debugging session.
The verbal greeting saw as a reference that points to an array with two string values.
Farewell was a reference that points to a copy of the original array, and so both variables are completely
independent of each other.
All right, now, debugging a one dimensional array is easy to erase are a different story.
So open up upper triangular java and the goal is to produce an upper triangular matrix from the two
Deira.
An upper triangular matrix is a two tier with zeros below the main diagonal.
If you're on the current code.
It's going to crash.
First step is to find out why something is wrong and using breakpoints, we can visualize the runtime
and figure it out.
Then launch a new debugging session.
And woops, it seems that every time the inner loop runs or increasing the outer loop counter, eventually
the outer loop counter exceeds the bounds of the array and crashes the up.
This mistake is so common and it can happen when you're not paying attention.
But seeing that runtime helps us debug the problem and see it right away.
All right, we run the code.
The nested loop sets every element to zero, that's not good.
If you look back at the output, only elements below the main diagonal should be zero.
Now it's hard to keep track of two counters at the same time.
And so this makes it hard to predict how we're going to use them to achieve our goal.
But it helps to launch a debugging session to visualize the runtime.
Hopefully then we can see a pattern.
And you know what, after visualizing the array without even stepping into the nested loop, the pattern
is clear.
The elements that need to be zero have a J index lower than the index.
So if Jay is smaller than I.
Then we're going to say matrix age is equal to zero.
All right, launch another debugging session to visualize the runtime.
And therein lies the beauty of visual analysis.
It helps to have a clear visual of what's going on instead of just looking at code.
And there's your upper triangular matrix.
In this lesson, you learn to debug using breakpoints now debugging in normal arrays, easy, but the
usage of a tutera implies a nested loop.
And so it's hard to keep track of the counters Ingi and how they're affecting your array.
But when you can visualize the runtime step by step, you can easily see how the state of the tiaro
is going to change.