[0.00 - 4.76] Hi, my name is Chandani and I'm one of the TAs for CSC 332 this quarter.
[5.38 - 11.18] And today I'm going to be doing a quick video on IntelliJ, which is an IDE or the code editor that
[11.18 - 16.06] we prefer students use this quarter for the programming projects. And this video will be
[16.06 - 21.22] covering some of the quick tricks that you can use to make your experience with IntelliJ easier,
[21.34 - 27.42] but also how to debug your program, which is going to be pretty invaluable for the larger
[27.42 - 32.46] programming assignments. So this video will be only covering some of the high level techniques,
[32.74 - 37.04] but there's so much more you can do with IntelliJ. So if you're interested in learning more,
[37.24 - 42.74] you can click on the handouts tab on the 332 website and go ahead and follow this first link.
[42.88 - 48.08] And if you scroll down a couple of pages, you'll see this entire section on creating an IntelliJ
[48.08 - 53.66] project, but more specifically, some of the tips that could be helpful in navigating IntelliJ.
[53.66 - 59.76] So to get started, instead of starting with the actual project, we're going to start off with this
[59.76 - 65.24] demo dummy project that is going to be used for the sake of getting familiar with the debugger.
[65.44 - 74.18] So the goal of this random method is to be able to take this input string and repeat each of the words
[74.18 - 80.56] in that string this given number of times. So for example, if I have a string called this is a sentence,
[80.56 - 87.16] this call to this method is expected to repeat each word in this method two times. So our expected output
[87.16 - 92.78] would look something along these lines. So let's say I've confidently written down this implementation,
[92.78 - 99.26] and I want to test out my program. So I'm going to go ahead and run my main method. And when I go ahead
[99.26 - 106.22] and run my main method, after this loads, I see that this output isn't quite what I expected over here.
[106.22 - 111.32] And more specifically, after looking at this for a bit, I see what's wrong is the fact that there's
[111.32 - 117.40] actually five of each word being printed out instead of two. So in this really small example,
[117.40 - 123.16] it's pretty easy to just look at the code and say what the error is. But in the case of your larger
[123.16 - 127.70] programming assignments, this is mostly never going to be the case when you have these smaller bugs.
[127.88 - 133.54] So we're going to pretend we don't know what's going on and continue to use the debugger to help us find
[133.54 - 138.12] the error with this program. So our first step to using the debugger is we're going to go ahead
[138.12 - 144.28] and set a breakpoint. So to do that, we go to this left panel over here and kind of click on the line.
[144.44 - 149.84] And what this breakpoint does is it's saying when we launch the debugger, we want our program's
[149.84 - 155.72] execution to stop at this line. And the reason I'm putting it here because I feel pretty confident
[155.72 - 160.94] that the thing that's going wrong with our program is going to be in this method repeat words.
[160.94 - 166.54] So once I set that breakpoint, I can go ahead and launch our debugger. There's a couple different
[166.54 - 171.64] ways you can launch this debugger. You can go over here, or you can also launch the debugger from this
[171.64 - 178.04] top panel over here by clicking debug. So our debugger is now launched. We see this wonderful panel over
[178.04 - 184.18] here that helps us navigate the debugger. So some things to note here is we have this pane called
[184.18 - 190.92] variables that keeps track of all the variables in the current scope of execution. So I'm currently on this
[190.92 - 196.12] line. And these are the variables that we've seen in this scope, and it keeps track of the values of
[196.12 - 201.10] these variables. So this can be especially helpful when we have a lot of different variables we're
[201.10 - 207.54] using in a method, especially when we're implementing big data structures, such as a hashtag map where we
[207.54 - 213.84] have different nodes and edges that we want to keep track of. So once we've launched this debugger,
[213.98 - 217.78] we want to figure out how we can move through the different lines of code. So to do this,
[217.78 - 223.70] we have a couple different options. So our first option is to click the step over button. So what
[223.70 - 230.44] the step over button does is it immediately moves on or steps over to the next possible line of code
[230.44 - 236.10] in the method that you're in. So although we have this method called to repeat words,
[236.56 - 242.56] the program is going to execute that separately and just move us on to the next line instead of stepping
[242.56 - 247.88] us through this method repeat words. So if I click on this, we simply move on to the next line in this
[247.88 - 253.84] method, which is the end of the method. So we didn't really get much out of debugging with a step over
[253.84 - 259.76] in this case, since we didn't even look into the method that was in question. An example of when step
[259.76 - 265.94] over could be useful is if you have a large method that calls a bunch of helper methods, but you feel
[265.94 - 270.96] confident that the helper methods are working correctly, you can use the step over to make sure you don't waste time
[270.96 - 275.96] having to go through each of those lines. So this time, we actually don't want to do step over since
[275.96 - 281.78] that wasn't really helpful in finding our bugs. So instead, we use the step into button over here,
[281.92 - 289.24] which allows us to directly step into the execution of that method call. So when I click step in,
[289.42 - 295.16] it's going to see that method and actually go into that method line by line. So I've stepped into a
[295.16 - 301.22] repeat words method. And you can see here that the variables available whose values we see change
[301.22 - 307.52] because we're now in this new scope of this method. So I'm going to continue to use the step into button.
[308.02 - 312.72] So in the case where I don't really have a specific method call, and I click step into,
[312.90 - 318.06] it's going to work very similar to the step over. So that's why I'm able to click this. So we're going to
[318.06 - 324.50] go into our loop, and we go into our nested loop. And we see these variables increasing since we have a lot
[324.50 - 330.58] more variables that we've seen when we got into this line in the code. And now I feel pretty confident
[330.58 - 336.68] that my print word method is working correctly. So here, I use the step over to say, let's go to the
[336.68 - 342.52] next side of the next iteration of the for loop. But if I really wanted to go into this print word
[342.52 - 348.90] method, I would then click the step into to once again, go into this method. And let's say now that
[348.90 - 354.36] I've stepped into this method, let's pretend there is a lot more to see here. And for example,
[354.36 - 358.74] I'm pretty sure I don't want to continue going through this helper method, I can use this button
[358.74 - 365.68] step out to go back to that previous function call or method call and start iterating from here. So
[365.68 - 372.68] we've seen step over, step into and step out, which allows us to step out of a method. So once we've
[372.68 - 378.64] stepped out, we're back to this for loop. And I'm going to continue using the step over since I'm not
[378.64 - 384.96] really interested in going into any helper methods. And once I do this, I take a look at this variables
[384.96 - 391.26] tab over here. And I noticed that my eye has incremented to three. So I'm continuously looping
[391.26 - 397.38] past the original input, which was two. So I thought I'd only be repeating this word twice. But now our
[397.38 - 402.96] loop has incremented to three, which is not what I expected. And if I go and look over here to why that
[402.96 - 408.98] is happening, I noticed that my eye is set to continue till it's less than five, rather than the
[408.98 - 416.46] input num. So I've now caught my error. And if I try running my program all over again, since I feel
[416.46 - 422.76] pretty sure that I've identified the issue, we see that it finally works as expected. So the key
[422.76 - 429.12] takeaways from debugging are setting breakpoints where you want to stop execution using step over, step into,
[429.12 - 434.10] and step out. Those are probably the most helpful. There's a lot of other tools with the debugger,
[434.14 - 438.80] but that's probably what's going to be the most relevant for this project. And also paying attention
[438.80 - 444.98] to the variables pane in the debugger. So now that we've looked at debugging in this simple example,
[445.22 - 451.20] we're going to go over to project one here, this is just the basic infrastructure code that we provided.
[451.52 - 458.00] So most of the times in your project, you're going to be debugging test cases rather than some main
[458.00 - 465.74] method as I did in my example. So one useful tip on IntelliJ is if you want to look for a file or some
[465.74 - 471.48] kind of function, you can double tap on shift and you get this sort of search pane over here. So
[472.16 - 477.26] let's say I didn't really know what I was looking for. I wanted the circular array queue test, but I
[477.26 - 484.04] don't remember the file name. I can start off by typing circular array FIFO, and I see that it directly
[484.04 - 491.02] gives me an option of the test files over here. So once I go to the test files, I'm not going to
[491.02 - 496.18] re-demo with this, but the same idea, you can set a breakpoint where you wish to stop that test case.
[496.40 - 501.64] And then same idea of if I want to step into where this object is actually being constructed,
[501.64 - 507.78] I can do so by using the step into method or use the step over to just go through this test case itself.
[507.78 - 515.44] So that will definitely be helpful in P1 and P2. And another cool thing that you can do is,
[515.64 - 521.78] let's say I'm going to search over and go to the actual circular FIFO queue file, and I'm working on
[521.78 - 528.62] my implementation for something like compare to, and I see this type called fixed size FIFO worklist,
[528.74 - 533.96] which I'm not familiar with. So instead of having to go through this entire directory
[533.96 - 540.02] one by one and try to figure out where fixed size FIFO worklist is, or even have to search for it,
[540.14 - 546.36] a really cool trick that I've found to be super helpful in this class is to use command click or
[546.36 - 551.74] control click depending on whether you're using a Mac. So if you're using a Mac, you do command click or
[551.74 - 557.36] otherwise control click. And if you click on the unknown type, it'll directly lead you to the
[557.36 - 563.12] implementation of that type. So you can quickly read through that and get an understanding of what you're
[563.12 - 568.86] looking at. So it's just a really quick way to get to the implementation of something that we've
[568.86 - 574.78] provided that you might not necessarily be familiar with. So it saves a lot of time with navigation.
[576.06 - 583.92] So that is our quick IntelliJ tutorial. We covered as a recap debugging, efficient way to search and also
[583.92 - 591.02] control click. So these tools should hopefully help you navigate P1 and P2 and P3 a little bit faster.
[591.02 - 595.98] But if not, there's a lot more you can do feel free to check out the handout, come to office hours,
[596.24 - 600.20] or just look and Google and see what else you can do with IntelliJ.
[600.20 - 600.34] So let's go ahead and see what else you can do with the handout.
[600.34 - 600.40] So let's go ahead and see what else you can do with the handout.
[600.40 - 600.44] So let's go ahead and see what else you can do with the handout.
[600.44 - 600.48] So let's go ahead and see what else you can do with the handout.
[600.48 - 600.56] So let's go ahead and see what else you can do with the handout.
[600.56 - 600.86] So let's go ahead and see what else you can do with the handout.
