This video is for Mac.
If you're using a Windows computer, please go to the next lesson.
Every developer should know how to use their terminal.
So far, you learned how to run your code using the run button.
Now, the run button is nice, but it's really important that you learn how to use your terminal.
So in this lesson, you will run your code using terminal commands.
Java C means Java compiler.
So in step one, the Terminal command Java C is going to compile your Java code into bytecode.
Specifically, we want to compile the code inside of Helo Java Java.
So tell your terminal we want the Java compiler Java C to compile the code inside of Hello, Java.
Java.
By doing so, the Java compiler will compile all of the Java code into a format called Bytecode.
The compiled bytecode is going to live inside of a dot class file.
From Vsco.
You can open up a new terminal by going over to terminal.
New terminal.
If the debug console shows up for you, feel free to dismiss it.
And your terminal should automatically point to section one the Hello Java Java file that lives inside
of Section one.
So over here we can compile the code inside of it.
Java Compiler and Java C.
And now press tab.
By pressing tab.
It guesses the file that I'm trying to compile by looking inside of the folder Section one.
There's only one file inside of section one so it auto completes.
Hello.
Java.
And now you can compile your Java code.
But anyways, by applying the Java Command on our Java file, the Java compiler compiled all of its
Java code into byte code, and the byte code lives inside of a dot class file.
In step number two, the Terminal command Java executes the compiled code.
So to summarize, the Java Sea Command compiles your code.
And the Java Command executes the compiled code by design.
The Java Sea Command includes the Java extension.
The Java Command does not.
So please be very careful when writing your commands.
All right, Back to our project.
We will write Java and then press tab.
It's going to autocomplete based on what it finds inside of Section one.
Do not add a Java extension at the end.
Just like that, it's able to run the compiled code.
What these two commands are doing is pretty much what the run button was doing for us behind the scenes.
But I want you to be comfortable running terminal commands, so I'm going to keep using terminal commands
throughout this course.
Now, let's say I want to re execute the compiled code instead of rewriting this command.
What I can do is press the up key.
The up key remembers previous terminal commands and we can use it to re execute the compiled code as
many times as we want.
Awesome.
Remember that when you execute your code, Java looks for the entry point main, it tries to find it
and once it finds main, it runs the code inside the first line of code inside main prints.
Hello Java.
Then it looks for more code inside main, but there isn't any so it reaches the end.
All right.
With that being said, I need to warn you to always compile your code first.
When you make changes to your code, compile it first using Java C and then run the compiled code using
the Java Command.
Let's look at an example where I don't do that, so I'm going to change the message to Greetings Java.
And now I would expect that by running this code, it should print this message.
So just run the code without compiling Java.
Hello?
Java.
And it still prints.
Hello, Java.
And that's because you're running the old compiled code.
When you make changes to your code, you need to recompile it using Java Sea.
Java Sea.
Hello?
Java.
And then execute the newly compiled code with the Java Command.
Java.
Hello, Java.
And once you do that, it executes the new code.
With that being said, congratulations.
You executed your code using Java commands.
So far you learn that all of your code must exist in a Java class.
You created a class called Hello Java.
Manage the entry point.
This is where Java starts running your code.
And finally, you can use the Java Sea Command to compile your code and the Java Command to execute
the compiled code.