1
00:00:00,090 --> 00:00:01,390
This video is for Mac.

2
00:00:01,410 --> 00:00:04,800
If you're using a Windows computer, please go to the next 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,380 --> 00:00:26,250
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,800 --> 00:00:39,890
So in step one, the Terminal command Java C is going to compile your Java code into bytecode.

9
00:00:43,710 --> 00:00:47,670
Specifically, we want to compile the code inside of Helo Java Java.

10
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.

11
00:00:57,650 --> 00:00:58,310
Java.

12
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.

13
00:01:09,420 --> 00:01:13,140
The compiled bytecode is going to live inside of a dot class file.

14
00:01:16,330 --> 00:01:17,230
From Vsco.

15
00:01:17,230 --> 00:01:20,290
You can open up a new terminal by going over to terminal.

16
00:01:20,440 --> 00:01:21,430
New terminal.

17
00:01:22,750 --> 00:01:26,230
If the debug console shows up for you, feel free to dismiss it.

18
00:01:27,000 --> 00:01:34,680
And your terminal should automatically point to section one the Hello Java Java file that lives inside

19
00:01:34,680 --> 00:01:35,550
of Section one.

20
00:01:35,550 --> 00:01:38,420
So over here we can compile the code inside of it.

21
00:01:38,430 --> 00:01:40,380
Java Compiler and Java C.

22
00:01:41,590 --> 00:01:43,330
And now press tab.

23
00:01:44,000 --> 00:01:45,140
By pressing tab.

24
00:01:45,140 --> 00:01:49,810
It guesses the file that I'm trying to compile by looking inside of the folder Section one.

25
00:01:49,820 --> 00:01:53,110
There's only one file inside of section one so it auto completes.

26
00:01:53,120 --> 00:01:53,450
Hello.

27
00:01:53,450 --> 00:01:53,930
Java.

28
00:01:53,930 --> 00:01:54,500
Java.

29
00:01:55,940 --> 00:01:58,460
And now you can compile your Java code.

30
00:02:04,990 --> 00:02:11,740
But anyways, by applying the Java Command on our Java file, the Java compiler compiled all of its

31
00:02:11,740 --> 00:02:16,720
Java code into byte code, and the byte code lives inside of a dot class file.

32
00:02:20,250 --> 00:02:25,440
In step number two, the Terminal command Java executes the compiled code.

33
00:02:28,940 --> 00:02:33,020
So to summarize, the Java Sea Command compiles your code.

34
00:02:34,680 --> 00:02:39,020
And the Java Command executes the compiled code by design.

35
00:02:39,030 --> 00:02:42,290
The Java Sea Command includes the Java extension.

36
00:02:42,300 --> 00:02:44,460
The Java Command does not.

37
00:02:44,490 --> 00:02:48,120
So please be very careful when writing your commands.

38
00:02:48,780 --> 00:02:50,400
All right, Back to our project.

39
00:02:50,400 --> 00:02:53,880
We will write Java and then press tab.

40
00:02:53,910 --> 00:02:57,720
It's going to autocomplete based on what it finds inside of Section one.

41
00:02:57,750 --> 00:03:00,900
Do not add a Java extension at the end.

42
00:03:02,000 --> 00:03:05,300
Just like that, it's able to run the compiled code.

43
00:03:07,080 --> 00:03:12,210
What these two commands are doing is pretty much what the run button was doing for us behind the scenes.

44
00:03:12,210 --> 00:03:16,950
But I want you to be comfortable running terminal commands, so I'm going to keep using terminal commands

45
00:03:16,950 --> 00:03:18,210
throughout this course.

46
00:03:18,420 --> 00:03:23,960
Now, let's say I want to re execute the compiled code instead of rewriting this command.

47
00:03:23,970 --> 00:03:26,070
What I can do is press the up key.

48
00:03:26,310 --> 00:03:31,560
The up key remembers previous terminal commands and we can use it to re execute the compiled code as

49
00:03:31,560 --> 00:03:33,120
many times as we want.

50
00:03:33,980 --> 00:03:34,700
Awesome.

51
00:03:37,210 --> 00:03:42,850
Remember that when you execute your code, Java looks for the entry point main, it tries to find it

52
00:03:42,850 --> 00:03:48,360
and once it finds main, it runs the code inside the first line of code inside main prints.

53
00:03:48,370 --> 00:03:49,480
Hello Java.

54
00:03:49,930 --> 00:03:54,670
Then it looks for more code inside main, but there isn't any so it reaches the end.

55
00:03:55,600 --> 00:03:56,130
All right.

56
00:03:56,140 --> 00:04:00,520
With that being said, I need to warn you to always compile your code first.

57
00:04:01,190 --> 00:04:07,670
When you make changes to your code, compile it first using Java C and then run the compiled code using

58
00:04:07,670 --> 00:04:08,960
the Java Command.

59
00:04:09,590 --> 00:04:16,190
Let's look at an example where I don't do that, so I'm going to change the message to Greetings Java.

60
00:04:18,459 --> 00:04:23,050
And now I would expect that by running this code, it should print this message.

61
00:04:23,290 --> 00:04:26,440
So just run the code without compiling Java.

62
00:04:26,470 --> 00:04:26,830
Hello?

63
00:04:26,830 --> 00:04:27,490
Java.

64
00:04:30,710 --> 00:04:31,640
And it still prints.

65
00:04:31,640 --> 00:04:32,450
Hello, Java.

66
00:04:32,450 --> 00:04:35,870
And that's because you're running the old compiled code.

67
00:04:36,720 --> 00:04:41,430
When you make changes to your code, you need to recompile it using Java Sea.

68
00:04:41,850 --> 00:04:42,650
Java Sea.

69
00:04:42,720 --> 00:04:43,140
Hello?

70
00:04:43,140 --> 00:04:43,500
Java.

71
00:04:43,710 --> 00:04:44,370
Java.

72
00:04:47,970 --> 00:04:51,840
And then execute the newly compiled code with the Java Command.

73
00:04:52,050 --> 00:04:52,680
Java.

74
00:04:52,680 --> 00:04:53,730
Hello, Java.

75
00:04:54,300 --> 00:04:57,210
And once you do that, it executes the new code.

76
00:04:58,500 --> 00:05:00,330
With that being said, congratulations.

77
00:05:00,330 --> 00:05:03,150
You executed your code using Java commands.

78
00:05:03,240 --> 00:05:07,080
So far you learn that all of your code must exist in a Java class.

79
00:05:07,470 --> 00:05:09,840
You created a class called Hello Java.

80
00:05:10,690 --> 00:05:12,070
Manage the entry point.

81
00:05:12,070 --> 00:05:14,230
This is where Java starts running your code.

82
00:05:19,190 --> 00:05:25,250
And finally, you can use the Java Sea Command to compile your code and the Java Command to execute

83
00:05:25,250 --> 00:05:26,420
the compiled code.

