1 00:00:00,180 --> 00:00:01,850 This video was for Windows. 2 00:00:01,859 --> 00:00:05,430 If you're using a mac computer, please go to the previous lesson. 3 00:00:06,650 --> 00:00:09,410 Every developer should know how to use their terminal. 4 00:00:11,730 --> 00:00:14,820 So far, you learned how to run your code using the run button. 5 00:00:15,060 --> 00:00:19,530 Now, the run button is nice, but it's really important that you learn how to use your terminal. 6 00:00:22,350 --> 00:00:26,220 So in this lesson, you will run your code using terminal commands. 7 00:00:28,790 --> 00:00:31,640 Java C means Java compiler. 8 00:00:33,810 --> 00:00:39,900 So in step one, the Terminal command Java C is going to compile your Java code into byte code. 9 00:00:43,720 --> 00:00:46,840 Specifically, we want to compile the code inside of Hello, Java. 10 00:00:47,020 --> 00:00:47,650 Java. 11 00:00:50,990 --> 00:00:57,380 So tell your terminal we want the Java compiler Java C to compile the code inside of Hello, Java. 12 00:00:57,650 --> 00:00:58,310 Java. 13 00:01:01,090 --> 00:01:07,420 By doing so, the Java compiler will compile all of the Java code into a format called Bytecode. 14 00:01:09,420 --> 00:01:13,140 The compiled bytecode is going to live inside of a class file. 15 00:01:16,350 --> 00:01:17,220 From Vsco. 16 00:01:17,250 --> 00:01:20,280 You can open up a new terminal by going over to terminal. 17 00:01:20,430 --> 00:01:21,420 New terminal. 18 00:01:25,940 --> 00:01:30,020 And your terminal should automatically point to section one. 19 00:01:31,670 --> 00:01:35,360 The Hello Java Java file that lives inside of Section one. 20 00:01:35,360 --> 00:01:38,260 So over here we can compile the code inside of it. 21 00:01:38,270 --> 00:01:40,220 Java Compiler and Java C. 22 00:01:41,400 --> 00:01:43,140 And now press tab. 23 00:01:43,840 --> 00:01:44,950 By pressing tab. 24 00:01:44,950 --> 00:01:48,820 It guesses the file that I'm trying to compile by looking inside of the folder. 25 00:01:48,820 --> 00:01:49,640 Section one. 26 00:01:49,660 --> 00:01:52,940 There's only one file inside of section one, so it auto completes. 27 00:01:52,960 --> 00:01:53,290 Hello. 28 00:01:53,290 --> 00:01:53,590 Java. 29 00:01:53,770 --> 00:01:54,320 Java. 30 00:01:54,340 --> 00:01:57,340 Because you're using PowerShell, it adds a dot slash. 31 00:01:57,340 --> 00:01:59,380 Please remove the dot slash. 32 00:02:01,900 --> 00:02:04,420 And now you can compile your Java code. 33 00:02:12,780 --> 00:02:19,380 But anyways, by applying the Java Sea Command on our Java file, the Java compiler compiled all of 34 00:02:19,380 --> 00:02:24,510 its Java code into byte code, and the byte code lives inside of a dot class file. 35 00:02:28,070 --> 00:02:33,230 In step number two, the Terminal command Java executes the compiled code. 36 00:02:36,740 --> 00:02:40,820 So to summarize, the Java Sea Command compiles your code. 37 00:02:42,510 --> 00:02:46,820 And the Java Command executes the compiled code by design. 38 00:02:46,830 --> 00:02:50,090 The Java Sea Command includes the Java extension. 39 00:02:50,100 --> 00:02:52,260 The Java Command does not. 40 00:02:52,290 --> 00:02:55,890 So please be very careful when writing your commands. 41 00:02:56,550 --> 00:02:58,200 All right, Back to our project. 42 00:02:58,200 --> 00:03:01,680 We will write Java and then press tab. 43 00:03:01,710 --> 00:03:05,610 It's going to autocomplete based on what it finds inside of section one. 44 00:03:05,610 --> 00:03:07,980 And here it adds a dot class at the end. 45 00:03:08,010 --> 00:03:13,440 Now, I know that the Java Command is ultimately executing the byte code inside of the class file, 46 00:03:13,440 --> 00:03:19,680 but by design, the Java Command does not have any extensions at the end, so please remove it. 47 00:03:19,710 --> 00:03:21,240 Do not add a dot class. 48 00:03:21,240 --> 00:03:24,150 Do not add a java Java file name. 49 00:03:24,150 --> 00:03:25,140 That's it. 50 00:03:25,260 --> 00:03:27,060 It also adds a dot slash. 51 00:03:27,060 --> 00:03:28,620 Please remove that as well. 52 00:03:31,730 --> 00:03:35,030 Just like that, it's able to run the compiled code. 53 00:03:35,420 --> 00:03:40,550 What these two commands are doing is pretty much what their run button was doing for us behind the scenes. 54 00:03:40,550 --> 00:03:45,290 But I want you to be comfortable running terminal commands, so I'm going to keep using terminal commands 55 00:03:45,290 --> 00:03:46,550 throughout this course. 56 00:03:46,760 --> 00:03:52,270 Now let's say I want to re execute the compiled code instead of rewriting this command. 57 00:03:52,280 --> 00:03:54,410 What I can do is press the up key. 58 00:03:54,620 --> 00:03:59,900 The up key remembers previous terminal commands and we can use it to re execute the compiled code as 59 00:03:59,900 --> 00:04:01,460 many times as we want. 60 00:04:02,320 --> 00:04:03,040 Awesome. 61 00:04:05,520 --> 00:04:11,190 Remember that when you execute your code, Java looks for the entry point main, it tries to find it 62 00:04:11,190 --> 00:04:16,680 and once it finds main, it runs the code inside the first line of code inside main prints. 63 00:04:16,680 --> 00:04:17,790 Hello Java. 64 00:04:18,269 --> 00:04:23,010 Then it looks for more code inside main, but there isn't any so it reaches the end. 65 00:04:23,930 --> 00:04:24,490 All right. 66 00:04:24,500 --> 00:04:28,880 With that being said, I need to warn you to always compile your code first. 67 00:04:29,540 --> 00:04:35,990 When you make changes to your code, compile it first using Java C and then run the compiled code using 68 00:04:35,990 --> 00:04:37,310 the Java Command. 69 00:04:37,940 --> 00:04:44,540 Let's look at an example where I don't do that, so I'm going to change the message to Greetings Java. 70 00:04:46,790 --> 00:04:51,380 And now I would expect that by running this code, it should print this message. 71 00:04:51,620 --> 00:04:54,780 So just run the code without compiling Java. 72 00:04:54,800 --> 00:04:55,160 Hello. 73 00:04:55,160 --> 00:04:55,820 Java. 74 00:04:56,480 --> 00:04:57,470 And it still prints. 75 00:04:57,470 --> 00:04:57,830 Hello? 76 00:04:57,830 --> 00:04:58,280 Java. 77 00:04:58,280 --> 00:05:01,700 And that's because you're running the old compiled code. 78 00:05:02,570 --> 00:05:07,280 When you make changes to your code, you need to recompile it using Java Sea. 79 00:05:07,670 --> 00:05:08,500 Java Sea. 80 00:05:08,540 --> 00:05:08,960 Hello? 81 00:05:08,960 --> 00:05:09,320 Java. 82 00:05:09,560 --> 00:05:10,190 Java. 83 00:05:11,030 --> 00:05:14,900 And then execute the newly compiled code with the Java Command. 84 00:05:15,050 --> 00:05:15,710 Java. 85 00:05:15,710 --> 00:05:16,790 Hello, Java. 86 00:05:17,330 --> 00:05:20,270 And once you do that, it executes the new code. 87 00:05:21,560 --> 00:05:23,360 With that being said, congratulations. 88 00:05:23,360 --> 00:05:26,180 You executed your code using Java commands. 89 00:05:26,270 --> 00:05:30,110 So far you learn that all of your code must exist in a Java class. 90 00:05:30,500 --> 00:05:32,870 You created a class called Hello Java. 91 00:05:33,730 --> 00:05:35,110 Manage the entry point. 92 00:05:35,110 --> 00:05:37,270 This is where Java starts running your code. 93 00:05:42,200 --> 00:05:48,290 And finally, you can use the Java Sea Command to compile your code and the Java Command to execute 94 00:05:48,290 --> 00:05:49,460 the compiled code.