1 00:00:00,200 --> 00:00:03,070 So now that we know how to get our code into the editor, 2 00:00:03,070 --> 00:00:05,370 let's take a quick look at how to execute it. 3 00:00:05,370 --> 00:00:09,190 In WorkSpaces we built our application by manually kicking off the compiler, 4 00:00:09,190 --> 00:00:13,510 Java C, which created Java class files containing the byte code. 5 00:00:13,510 --> 00:00:15,650 Then we ran the Java executable and 6 00:00:15,650 --> 00:00:18,410 passed in the name of the class that contained our starting point. 7 00:00:18,410 --> 00:00:19,769 You know, the static main method. 8 00:00:20,840 --> 00:00:23,500 Well I'm glad that we learned how to do that it will help 9 00:00:23,500 --> 00:00:27,480 demystify the compilation and running process that you are about to see. 10 00:00:27,480 --> 00:00:29,650 The IDE does all that and more. 11 00:00:29,650 --> 00:00:30,640 Ready to learn how? 12 00:00:30,640 --> 00:00:31,260 Let's go take a look. 13 00:00:33,000 --> 00:00:36,830 Okay so the first thing to remember is that you can have multiple modules and 14 00:00:36,830 --> 00:00:40,030 therefore it's possible that you can have static main methods in 15 00:00:40,030 --> 00:00:41,730 any of those files that you want to run. 16 00:00:41,730 --> 00:00:45,690 And there's no real way that the ID could possibly know which file 17 00:00:45,690 --> 00:00:47,130 you wanna execute. 18 00:00:47,130 --> 00:00:51,840 So the idea in running something is to first find the file that you wanna run. 19 00:00:51,840 --> 00:00:55,270 So, I know that our file that we ran before was called Karaoke. 20 00:00:56,360 --> 00:00:58,910 And I know it's a little confusing it's the Karaoke project. 21 00:00:58,910 --> 00:00:59,860 It's the Karaoke file. 22 00:00:59,860 --> 00:01:01,180 There's also a karaoke machine. 23 00:01:01,180 --> 00:01:03,530 We should probably rename that in the future sometime. 24 00:01:03,530 --> 00:01:04,570 For now let's open it. 25 00:01:04,570 --> 00:01:10,440 And let's say that I didn't want to use the mouse to click over there. 26 00:01:10,440 --> 00:01:11,620 If I come over here and 27 00:01:11,620 --> 00:01:15,180 press double shift, there's a great tool called Search Everywhere. 28 00:01:15,180 --> 00:01:17,820 I'm just going to start typing karaoke. 29 00:01:17,820 --> 00:01:21,740 There it is, classes, I'm going to choose that and I'm going to press Enter, boom. 30 00:01:21,740 --> 00:01:24,240 There's our Karaoke file, great. 31 00:01:24,240 --> 00:01:25,550 This is what I want to run, right? 32 00:01:25,550 --> 00:01:27,600 Remember this goes and starts every thing off. 33 00:01:27,600 --> 00:01:31,470 So since I have it open, I'm going to go to the run menu, and 34 00:01:31,470 --> 00:01:32,720 I'm just going to choose run here. 35 00:01:34,300 --> 00:01:37,480 Now it's just double-checking what I meant, and 36 00:01:37,480 --> 00:01:41,120 it's gonna do this here, Karaoke, and I'm gonna click this. 37 00:01:41,120 --> 00:01:43,090 It's gonna go ahead and it's gonna build the file. 38 00:01:44,120 --> 00:01:47,000 After it's built, we'll take a look at how it got ran. 39 00:01:48,440 --> 00:01:52,520 Okay, so it's gonna pop up a new window here called the console. 40 00:01:52,520 --> 00:01:56,350 And here, you'll see that the program's actually running and it's waiting for 41 00:01:56,350 --> 00:01:57,450 our input. 42 00:01:57,450 --> 00:01:59,070 Here's the program that got kicked off and 43 00:01:59,070 --> 00:02:02,170 I just kinda wanna show you all the way over here to the end. 44 00:02:02,170 --> 00:02:07,340 That's kind of a crazy set up, but it's running basically what we did, 45 00:02:07,340 --> 00:02:12,010 but it's wrapping it in this IDE magic and what that does is it allows us to. 46 00:02:12,010 --> 00:02:14,990 Type into this window, and it allows system out to come into here. 47 00:02:14,990 --> 00:02:18,900 So right, so system in is coming in and capturing it, and it's wrapping it. 48 00:02:18,900 --> 00:02:21,121 But it's still passing at this parameter here. 49 00:02:24,180 --> 00:02:25,868 So let me scroll all the way back. 50 00:02:25,868 --> 00:02:28,034 Okay, cool. 51 00:02:28,034 --> 00:02:29,630 So, what do we wanna do? 52 00:02:29,630 --> 00:02:31,270 Let's choose a song to sing. 53 00:02:31,270 --> 00:02:32,410 Right? 54 00:02:32,410 --> 00:02:33,480 Let's choose YouTube. 55 00:02:34,650 --> 00:02:36,920 And I still haven't found what I'm looking for. 56 00:02:38,330 --> 00:02:39,510 Okay, great. 57 00:02:39,510 --> 00:02:41,660 So it's pretty cool right? 58 00:02:41,660 --> 00:02:44,655 Now the bummer is that in a few of our apps we used 59 00:02:44,655 --> 00:02:50,270 system.console which is specifically made for console apps by the Java team. 60 00:02:50,270 --> 00:02:51,070 So the bad news is. 61 00:02:51,070 --> 00:02:53,700 And you might have heard some chatter about this in the forum. 62 00:02:53,700 --> 00:02:58,430 The don't work so well in this redirected IO model that most of these IDEs use. 63 00:02:58,430 --> 00:02:59,890 Right? So the way that they're writing to 64 00:02:59,890 --> 00:03:01,930 the window and reading from the window. 65 00:03:01,930 --> 00:03:06,270 So currently there are bugs filed in almost all of the popular IDEs that I saw 66 00:03:06,270 --> 00:03:10,240 to support the system.console bug, but the big problem is, 67 00:03:10,240 --> 00:03:11,710 is that console is marked final. 68 00:03:11,710 --> 00:03:12,860 Remember that can't be changed. 69 00:03:12,860 --> 00:03:15,510 So it's pretty hard for these IDE maintainers to get things right. 70 00:03:15,510 --> 00:03:16,500 So you can't really blame them. 71 00:03:18,060 --> 00:03:20,910 Maybe by the time you're watching this they'll already have it fixed. 72 00:03:20,910 --> 00:03:25,160 But if not, use the tricks that we use in this Karaoke app of using system out and 73 00:03:25,160 --> 00:03:27,450 system in as opposed to system dot council. 74 00:03:28,700 --> 00:03:32,210 I've included some notes about the problem in the teachers' notes. 75 00:03:32,210 --> 00:03:34,950 Now, since we've run this once what happened was it 76 00:03:34,950 --> 00:03:37,070 created a run configuration. 77 00:03:37,070 --> 00:03:39,970 So you'll see here in the menu that it has a Run Karaoke. 78 00:03:40,990 --> 00:03:42,010 Let's go ahead and click that again. 79 00:03:43,510 --> 00:03:47,610 So it's kicking it off again, and one thing that I really wanted to point out is 80 00:03:47,610 --> 00:03:50,840 that we left our first application still running over here, and 81 00:03:50,840 --> 00:03:52,090 there's another one running. 82 00:03:52,090 --> 00:03:53,880 So, it's running two. 83 00:03:53,880 --> 00:03:55,180 And that's totally fine, but 84 00:03:55,180 --> 00:03:57,550 you might forget and get a whole bunch of these going. 85 00:03:57,550 --> 00:04:00,610 So it's important to know that there's a little run menu over here, and 86 00:04:00,610 --> 00:04:01,900 you can stop things. 87 00:04:01,900 --> 00:04:03,080 So let's stop that Karaoke. 88 00:04:03,080 --> 00:04:07,110 Let this process finish, and we'll come over here. 89 00:04:07,110 --> 00:04:12,420 The other thing you could do is say Close, or Close Tab or Close All Tabs. 90 00:04:12,420 --> 00:04:15,120 And this is a pretty common thing to see. 91 00:04:15,120 --> 00:04:18,010 The Karaoke is running, we're just gonna say to disconnect and 92 00:04:18,010 --> 00:04:18,860 terminate the process. 93 00:04:18,860 --> 00:04:21,630 Boom, and now, well, our menu's gone from down there. 94 00:04:21,630 --> 00:04:25,530 Okay, so this is the runbar up here. 95 00:04:25,530 --> 00:04:26,630 You'll also see that 96 00:04:27,770 --> 00:04:30,210 all the different configurations that got built will be shown in here. 97 00:04:30,210 --> 00:04:33,670 So we just built that configuration for Karaoke so it's in here. 98 00:04:33,670 --> 00:04:36,840 So, let's go ahead and open up that configuration. 99 00:04:38,040 --> 00:04:40,620 Okay, cool. So these are the settings for it. 100 00:04:40,620 --> 00:04:42,690 You can set options for each time that the program runs. 101 00:04:42,690 --> 00:04:46,090 So remember in our Hangman app, we passed the name of the puzzle. 102 00:04:46,090 --> 00:04:48,500 That's what this Program arguments field is here. 103 00:04:48,500 --> 00:04:52,210 The Working directory is what is set from where things start. 104 00:04:52,210 --> 00:04:55,670 So if you remember, that's why we dropped the songs.txt. 105 00:04:55,670 --> 00:04:58,880 Right into the content route because this is the content route right. 106 00:04:58,880 --> 00:05:00,410 Karaoke, content route. 107 00:05:00,410 --> 00:05:03,740 So, that's where things work relatively. 108 00:05:03,740 --> 00:05:06,710 I don't know if you remember exactly where that is but 109 00:05:06,710 --> 00:05:08,680 I want to show you where we're doing this. 110 00:05:08,680 --> 00:05:11,470 So I know that we're doing this thing here. 111 00:05:11,470 --> 00:05:14,080 Called import from songs.text. 112 00:05:14,080 --> 00:05:17,080 So let's say that we didn't know where that songBook def was. 113 00:05:17,080 --> 00:05:18,730 But we knew that the function was called import from. 114 00:05:18,730 --> 00:05:21,880 So you can also sort modules right. 115 00:05:21,880 --> 00:05:24,110 So if I go import from and I hit it. 116 00:05:24,110 --> 00:05:25,740 It will go right to where it was at. 117 00:05:26,890 --> 00:05:28,020 And let's see. 118 00:05:28,020 --> 00:05:31,030 So it says a new import stream reader on the fileName and 119 00:05:31,030 --> 00:05:33,530 that was songs.text that we passed in and since. 120 00:05:33,530 --> 00:05:34,670 This thing works relatively. 121 00:05:34,670 --> 00:05:37,270 It's working from the working directory, which is right here. 122 00:05:38,430 --> 00:05:38,930 Cool right? 123 00:05:40,020 --> 00:05:42,240 Okay, so let's flip back really quick to that configuration. 124 00:05:42,240 --> 00:05:44,750 So I'm going to click this up here and choose that Configurations. 125 00:05:44,750 --> 00:05:48,530 I want to show you one more thing because it's kind of buried and 126 00:05:48,530 --> 00:05:51,820 I've seen some questions about this so I just want to make sure I point it out. 127 00:05:51,820 --> 00:05:54,330 Logging is a great tool that is available in Java and 128 00:05:54,330 --> 00:05:56,090 Java has a great logging system. 129 00:05:56,090 --> 00:06:00,870 It allows you to categorize and place entries of different severities and 130 00:06:00,870 --> 00:06:02,650 lets you know what's happening during your application. 131 00:06:02,650 --> 00:06:05,890 And maybe you don't want to show users what's happening during your application, 132 00:06:05,890 --> 00:06:08,060 but you do want to have logs of what was happening. 133 00:06:08,060 --> 00:06:11,540 So, there's a tab over here that says Logs and you can configure them here. 134 00:06:11,540 --> 00:06:13,900 You can save everything that happened to a console to a file. 135 00:06:13,900 --> 00:06:15,790 So, that's kind of helpful through debugging, 136 00:06:15,790 --> 00:06:17,790 if you wanted to get back to it later. 137 00:06:17,790 --> 00:06:22,780 And there's also the ability to show the console when it changes, 138 00:06:22,780 --> 00:06:24,780 which is also pretty nice. 139 00:06:24,780 --> 00:06:27,690 So the last thing that I want you to remember here is that you can have 140 00:06:27,690 --> 00:06:32,080 multiple modules with run configurations, and just remember that pressing 141 00:06:32,080 --> 00:06:35,550 this run button here will run whatever is in this list here. 142 00:06:35,550 --> 00:06:36,390 So this is Karaoke. 143 00:06:36,390 --> 00:06:40,667 So if I press play, it will run that specific configuration. 144 00:06:40,667 --> 00:06:42,540 Great, all right. 145 00:06:42,540 --> 00:06:45,430 So now we can navigate around our file structure, and build and 146 00:06:45,430 --> 00:06:46,870 run our application. 147 00:06:46,870 --> 00:06:49,310 There is a ton more of this ID you can do, 148 00:06:49,310 --> 00:06:52,220 and much more than I could possibly show you in this course. 149 00:06:52,220 --> 00:06:55,180 Let's spend a little time learning how to figure more out, and 150 00:06:55,180 --> 00:06:57,180 also let me show off a few of my favorite tricks.