课程: Java: Data Structures

Using the exercise files

- [Instructor] The examples and exercise files for this course is stored on GitHub. To download them, you'll need to have Git installed on your computer. So if you don't, you can go to git-scm.com/downloads, and there are options there to download Git for Mac or for windows. So there's a branch for every video where we work on code. All of my examples start with an empty class. So the code in the branches shows the end state of the code I'm demonstrating. You can view a list of all the branches right here in GitHub from the branch dropdown. So if I click up here where it says main, I'll actually get a dropdown which shows every branch available in this course. So if, for example, if I wanted to see the branch 02_02, I could click on it here and the page will update and show all the code for that video. I'm going to show you how to download the code using the command line. Your IDE might have tools to do this visually, which might be easier for you and feel free to use those if you want to. But if you do it from the command line, you can then open the code in any IDE and it will give you some useful practice with the Git commands too. So the first step is to copy the link for the repository. So I'm going to click on this green button here, where it says code. And if I click on these two little squares, it will copy the link for me. Next, I need to go to the command line. So I'm on a Mac, so I'm going to go to my terminal, or if you're on a windows computer, if you search for a command prompt, that will open up your command prompt there as well. Now, the first thing I need to do in here is I need to go to the directory where I want to save the code. The commands are changed directory and the command prompt is CD. So I'm going to type CD and I've got a folder called data structures in here. And a little tip, if you press tap in here, it will auto complete the name of your directory. So I'm going to CD into data structures. And you can save this any way you'd like on your computer. I've just created a folder called data structures where I'm going to save the code, but you can save it absolutely anywhere. Now I need to download the code and the commands for that is called Git clone. So I'm going to type Git clone. And then I can just paste the URL. I copy just now in the GitHub window. So I press Enter and that will download the code into my folder. The next step is to open the code in your IDE. I'm going to be using IntelliJ. So I'm going to open up IntelliJ and I click on this button here that says open. Then I just need to go to the folder where I saved the code. So I saved it in a folder called data structures. And in here, it will be called Java data structures, 300149. And I just click Open. So by default, the code will start off on the main branch. As I mentioned earlier, I've created branches for each video in the course where we modify code. If you'd like to follow along in IntelliJ, you can use the branches pop-up menu in the lower right-hand corner. So down here, there's a little branch symbol and it says main. So if I click on this, it will show a list of all the possible branches I can use. So let's say I want to go to 02_02. So I just click on here and then it will come up with a menu with checkouts at the top and I just click on Checkouts. Now you might see a little window down in the bottom right that says Maven build scripts found. And if you see that click on load Maven projects. Then you might get this second pop-up, which is asking you if you want to trust the Maven project. Feel free to click on trust project. So now I'm on the branch 02_02 and you can find the code in this source menu in main Java. And then there's a class here called array examples. So that's how you change branches inside IntelliJ ID. I'm going to show you how to get from the command line now as well in case we're using a different IDE or just want to get some practice using the command line. So I'm going to go back to my terminal. And the first thing I need to do here is I need to go into the directory where my code is saved. So it saved inside a folder called Java data structures, 3001429. And again, I'm pressing tap to auto complete and then answer. So now I'm inside that directory. The next thing I want to do is check out the branch I want. So let's say I want to check out 02_03. To do that, the command is Git, checkouts and then the name of the branch, so, 02_03 and then I press Enter and it switched to that new branch for me. So if I go back to IntelliJ now, I can see everything's updated. The branch has changed to 02_03. I can see down here in the bottom. And the code for this branch has loaded inside IntelliJ.

内容