1 00:00:01,020 --> 00:00:03,630 Okay, so remember that quiz question from a previous 2 00:00:03,630 --> 00:00:05,830 course where I asked about a dunk tank? 3 00:00:05,830 --> 00:00:08,920 Well some of you didn't know what that was and I apologize. 4 00:00:08,920 --> 00:00:12,920 It's a carnival game where someone sits over a pool of water on a shelf. 5 00:00:12,920 --> 00:00:16,070 The carnival-goer buys the balls and they throw it at the target. 6 00:00:16,070 --> 00:00:18,570 If they hit the target, the person falls into the water. 7 00:00:20,190 --> 00:00:23,650 Now I'm sure you're imagining putting me on that dunk tank and 8 00:00:23,650 --> 00:00:27,350 throwing the ball and having me dunked into freezing cold water, 9 00:00:27,350 --> 00:00:29,920 because I didn't show you these tools earlier. 10 00:00:29,920 --> 00:00:33,900 But, before you get too upset at me, let's take a second to appreciate that you were 11 00:00:33,900 --> 00:00:36,540 able to code in Java without these tools. 12 00:00:36,540 --> 00:00:38,880 You didn't need these training wheels on your editor. 13 00:00:38,880 --> 00:00:42,350 Let's be honest, most of the warnings wouldn't have made any sense to you at 14 00:00:42,350 --> 00:00:43,520 all until you got started. 15 00:00:44,580 --> 00:00:47,140 Now, that being said though, you can totally dunk me. 16 00:00:47,140 --> 00:00:48,440 I'm sure I deserve it. 17 00:00:48,440 --> 00:00:52,530 I did make you type a lot more than you would have to in a real world situation. 18 00:00:52,530 --> 00:00:56,350 So let's just say at this point, I definitely owe you three dunk tank balls. 19 00:00:56,350 --> 00:01:01,510 Alright, so let's import that very long project that you painstakingly 20 00:01:01,510 --> 00:01:06,100 completed without code assistance in the previous course, the karaoke machine. 21 00:01:06,100 --> 00:01:09,310 I want to show you how to bring outside code into this new world order. 22 00:01:10,970 --> 00:01:13,530 Okay, so I've included a zip file of 23 00:01:13,530 --> 00:01:16,580 the source code from the final project in the teacher's notes. 24 00:01:16,580 --> 00:01:20,370 If you want to get your own version, just go to your workspace and choose File > 25 00:01:20,370 --> 00:01:24,110 Download Workspace, and that will send down a ZIP file that you can then open up. 26 00:01:24,110 --> 00:01:26,870 So what I've done is I've downloaded that ZIP file, I've unzipped it, and 27 00:01:26,870 --> 00:01:28,870 now I have that source code in a folder. 28 00:01:28,870 --> 00:01:30,100 Here it is. 29 00:01:30,100 --> 00:01:32,910 Now, since we're just hand coding like this and there isn't 30 00:01:32,910 --> 00:01:37,080 any additional project information, let's first just create a new project. 31 00:01:37,080 --> 00:01:38,730 Okay. So, the way that you do that is, 32 00:01:38,730 --> 00:01:43,330 in IntelliJ you choose File > New > Project. 33 00:01:43,330 --> 00:01:45,500 Okay. And this is very much like the Create New 34 00:01:45,500 --> 00:01:50,070 Project that we saw before, and we wanna just leave it, the Project SDK the same. 35 00:01:50,070 --> 00:01:51,390 We don't wanna do a template, right? 36 00:01:51,390 --> 00:01:54,780 Because we've already got our code that we need, so we're just gonna go ahead and 37 00:01:54,780 --> 00:01:56,500 leave that unchecked. 38 00:01:56,500 --> 00:01:58,570 And we're gonna call this Karaoke. 39 00:02:01,350 --> 00:02:04,490 Okay. So, it's possible to have multiple windows 40 00:02:04,490 --> 00:02:07,640 open with different editors and that's what this prompt is asking. 41 00:02:07,640 --> 00:02:11,600 It's asking if we want to replace this window or if we wanna make a new one and 42 00:02:11,600 --> 00:02:12,890 have them side by side. 43 00:02:12,890 --> 00:02:14,740 For our case, we're just gonna use this one. 44 00:02:14,740 --> 00:02:17,470 So what it's gonna do is it's gonna get rid of the systemizer window that we have 45 00:02:17,470 --> 00:02:19,190 and we're gonna put up the karaoke window. 46 00:02:20,900 --> 00:02:21,560 Cool. 47 00:02:21,560 --> 00:02:24,020 So, this is an empty project. 48 00:02:24,020 --> 00:02:27,800 By default, the project is set up in a directory based format. 49 00:02:27,800 --> 00:02:31,080 When creating a project, a default module is added for us, and 50 00:02:31,080 --> 00:02:33,240 that's what this is here, this karaoke. 51 00:02:33,240 --> 00:02:38,800 Now a module in IntelliJ is defined as a discreet unit of functionality. 52 00:02:38,800 --> 00:02:43,010 Modules contain everything that is required for their specific task, and 53 00:02:43,010 --> 00:02:44,420 they come with an .idea folder. 54 00:02:44,420 --> 00:02:46,070 This .idea folder. 55 00:02:46,070 --> 00:02:48,220 It contains files about how you like your editor setup. 56 00:02:49,290 --> 00:02:51,710 They also have an IML file here, and 57 00:02:51,710 --> 00:02:54,790 it keeps project specific settings in one place. 58 00:02:54,790 --> 00:02:59,420 The .iml suffix stands for idea module, and the fact that all the settings are in 59 00:02:59,420 --> 00:03:02,990 a file like this, it makes sure that teams can have the same setup. 60 00:03:02,990 --> 00:03:06,520 So I could share this with somebody else and this setup would be the same. 61 00:03:06,520 --> 00:03:11,830 There's a little icon on this folder here, on the karaoke folder here of this module. 62 00:03:11,830 --> 00:03:16,590 And that's saying that it's the content root folder. This source folder here 63 00:03:16,590 --> 00:03:18,640 is short for source code. 64 00:03:18,640 --> 00:03:22,949 And it's blue you'll notice, and that blue represents that it's the source root. 65 00:03:22,949 --> 00:03:26,355 All other folders are sort of orange and yellow like that. 66 00:03:26,355 --> 00:03:30,580 If you're working with other projects from idea users or even Eclipse projects, 67 00:03:30,580 --> 00:03:32,480 you can actually import things really easy. 68 00:03:32,480 --> 00:03:36,400 So, you could get these IML files from other people like I was saying. 69 00:03:36,400 --> 00:03:39,090 But what I wanna show you here first is that when you don't 70 00:03:39,090 --> 00:03:42,340 have an existing idea project to import, like we don't currently, right? 71 00:03:42,340 --> 00:03:44,900 Our karaoke project is hand-coded. 72 00:03:44,900 --> 00:03:49,960 You can imagine this as kind of converting or upgrading to an idea project. 73 00:03:49,960 --> 00:03:53,120 These idea projects respond really well to dragging and dropping. 74 00:03:53,120 --> 00:03:59,630 So, I'm gonna go ahead and I am gonna grab the karaoke folder and our packages. 75 00:03:59,630 --> 00:04:01,420 And I'm gonna drag those and 76 00:04:01,420 --> 00:04:05,220 I'm gonna just click right inside the source file here, okay? 77 00:04:05,220 --> 00:04:07,830 And it's gonna go ahead and say move the specified references and 78 00:04:07,830 --> 00:04:08,340 that's fine, right? 79 00:04:08,340 --> 00:04:09,930 Cuz that was just a zip folder that I had. 80 00:04:09,930 --> 00:04:11,370 So I'm just gonna go ahead and move them. 81 00:04:11,370 --> 00:04:13,320 And it says open the moved files in the editor. 82 00:04:13,320 --> 00:04:13,820 Sure, why not? 83 00:04:15,970 --> 00:04:18,850 Okay, and it says they don't belong to the project. 84 00:04:18,850 --> 00:04:19,870 Okay I understand that. 85 00:04:19,870 --> 00:04:20,580 I'm moving them. 86 00:04:22,160 --> 00:04:27,060 And finally, I'm gonna bring this songs.txt to the content root. 87 00:04:27,060 --> 00:04:28,690 Right? So I'm gonna put it here. 88 00:04:28,690 --> 00:04:30,610 When we end up running this later and 89 00:04:30,610 --> 00:04:32,780 again it asks for the same things here again. 90 00:04:32,780 --> 00:04:36,650 Before we were running right from the start of the directory and 91 00:04:36,650 --> 00:04:37,610 this is relative. 92 00:04:37,610 --> 00:04:41,200 We'll explore this a little bit in the future when we go to run this. 93 00:04:41,200 --> 00:04:44,240 But I just wanted to point out that we don't want to drop it into source code 94 00:04:44,240 --> 00:04:47,860 folder, we're gonna put it in the content root, and I'll show you why here in a bit. 95 00:04:47,860 --> 00:04:52,350 Okay, so, I really wanna show you something that's gonna make you happy. 96 00:04:52,350 --> 00:04:55,430 So, you can set up these different formatting rules. 97 00:04:55,430 --> 00:04:57,680 So, here's our Song.java file. 98 00:04:57,680 --> 00:04:59,590 Now let's say that when we were coding, 99 00:04:59,590 --> 00:05:03,175 we weren't the cleanest about things about things that we kind of did. 100 00:05:03,175 --> 00:05:09,800 We move this over, got a warning up here about the file is indented with 101 00:05:09,800 --> 00:05:12,920 two spaces instead of four, and that's kind of the default here, in this world. 102 00:05:12,920 --> 00:05:14,105 And this is nice, right? 103 00:05:14,105 --> 00:05:16,950 Cuz if you have different team members working on different things. 104 00:05:16,950 --> 00:05:19,270 So, I'm just gonna screw up the spacing a little bit because, you know, 105 00:05:19,270 --> 00:05:23,440 we were rushing to get through this before and the spacing wasn't quite done. 106 00:05:23,440 --> 00:05:27,160 So, let's go ahead and come up here to code. 107 00:05:28,470 --> 00:05:35,299 And if you look down here in this code, there's this Reformat code, 108 00:05:35,299 --> 00:05:39,450 and that is Option+Command+L on a Mac. 109 00:05:39,450 --> 00:05:40,770 So I'm gonna go ahead and I'm gonna click that. 110 00:05:40,770 --> 00:05:42,060 Watch what it does. 111 00:05:42,060 --> 00:05:44,180 Boom. Everything got set the proper way and 112 00:05:44,180 --> 00:05:45,450 now it's also at four spaces. 113 00:05:45,450 --> 00:05:47,525 But look, everything's back to where it was. 114 00:05:47,525 --> 00:05:51,310 So, I am gonna do that again and I'm gonna do that again and 115 00:05:51,310 --> 00:05:54,322 we'll just bring this guy. 116 00:05:54,322 --> 00:05:57,980 It's pretty good at not letting me screw those up. 117 00:05:57,980 --> 00:06:02,010 So, I'm going to Option+Command+L and everything is back to normal. 118 00:06:02,010 --> 00:06:03,960 So it's Ctrl+Alt+L in Windows. 119 00:06:03,960 --> 00:06:04,700 That's great. 120 00:06:04,700 --> 00:06:08,340 But what if I knew that I remembered doing that one time, but 121 00:06:08,340 --> 00:06:09,590 I can't remember where it's at? 122 00:06:09,590 --> 00:06:12,520 So there's a great feature in IntelliJ whic will be your friend, 123 00:06:12,520 --> 00:06:14,170 especially when you're learning this. 124 00:06:14,170 --> 00:06:22,370 If you press Cmd+Shift+A, or Shift+Ctrl+A on Windows, and you choose. 125 00:06:22,370 --> 00:06:23,500 I know it wasn't Reformat. 126 00:06:25,270 --> 00:06:26,770 There it is, Reformat Code. 127 00:06:26,770 --> 00:06:27,705 And then, boom. 128 00:06:27,705 --> 00:06:29,300 And it will do it. 129 00:06:29,300 --> 00:06:34,044 And I have to break anything, let's break something real quick. 130 00:06:34,044 --> 00:06:38,192 So, Control+Shift+A, Reformat Code, boom, that fixed it. 131 00:06:38,192 --> 00:06:39,570 Great, right? 132 00:06:39,570 --> 00:06:44,880 So, we just did this file, but let's go ahead and open up another file over here. 133 00:06:44,880 --> 00:06:45,790 Let's open up Songbook. 134 00:06:46,830 --> 00:06:50,580 So we can go ahead and reformat the entire package. 135 00:06:50,580 --> 00:06:56,090 So, if I come up here to the source folder and I say Reformat Code, 136 00:06:57,850 --> 00:07:01,440 we're gonna include subdirectories and we're gonna leave Optimize Imports, right? 137 00:07:01,440 --> 00:07:05,550 So that's gonna remove any imports that we didn't use, cuz that can happen, and 138 00:07:05,550 --> 00:07:07,030 we're also gonna choose Rearrange Entry. 139 00:07:07,030 --> 00:07:07,690 So, I'm gonna click Run. 140 00:07:10,410 --> 00:07:12,380 So, now all the files, and 141 00:07:12,380 --> 00:07:16,265 we can open them up by clicking on them over here, are done. 142 00:07:16,265 --> 00:07:18,050 You also notice there's some of these pluses. 143 00:07:18,050 --> 00:07:21,940 This is here to kind of help you read your code quicker, but I'm gonna open this up. 144 00:07:23,100 --> 00:07:26,990 One more thing I wanted to show you really quick is, on the imports over here, 145 00:07:26,990 --> 00:07:30,090 remember we put the dot star, and I told you it was a little bit lazy? 146 00:07:30,090 --> 00:07:32,580 Well let's go ahead and let's put our cursor here and let's see what happens. 147 00:07:32,580 --> 00:07:34,240 Look, there's a little thing that popped up over here. 148 00:07:34,240 --> 00:07:37,710 This light bulb is called an intention action. 149 00:07:37,710 --> 00:07:40,910 What happens with these intention actions are they're suggestions 150 00:07:40,910 --> 00:07:42,130 of what could happen. 151 00:07:42,130 --> 00:07:46,120 So, let's go ahead and open this up and it says, replace with single class imports. 152 00:07:46,120 --> 00:07:47,500 That's great, that's exactly what we wanted. 153 00:07:47,500 --> 00:07:50,530 We just didn't want to have to type all those out, so let's do that. 154 00:07:50,530 --> 00:07:54,070 And what it did was it took an alphabetized order of everything that we 155 00:07:54,070 --> 00:07:56,670 used in here that was under that star. 156 00:07:56,670 --> 00:07:58,730 Pretty powerful tool, isn't it? 157 00:07:58,730 --> 00:08:00,580 Okay, we learned a ton there. 158 00:08:00,580 --> 00:08:01,150 And as I'm sure, 159 00:08:01,150 --> 00:08:04,955 you saw when you opened that menu up, there are a lot more actions in there. 160 00:08:04,955 --> 00:08:08,745 We definitely aren't gonna hit all of those, but in a bit, I'll show you how 161 00:08:08,745 --> 00:08:12,435 awesome the documentation is for the IntelliJ Idea Project. 162 00:08:12,435 --> 00:08:14,535 You can dive in at your own pace. 163 00:08:14,535 --> 00:08:16,925 So let's go ahead and take a quick break and I'll swing back and 164 00:08:16,925 --> 00:08:18,225 show you how to run our application.