In this chapter we are going to introduce Java programing
by writing the first program most programs write in a language.
A program that displays hello world on the screen.
In this first lesson we are going to see
how to enter the program into the text editor.
That is our first step.
The first thing we wanna do is open up a DOS prompt,
get to your documents folder, wherever your documents are stored, and then
to make it easy to retrieve the programs that we work on,
create a directory inside your documents folder, or create a folder called Java.
I'm doing it by typing md.Java for make directory.
Once you've done that then you can change directories
into that folder by typing CD Java for change directory.
And that puts us in the Java folder.
And now I'm gonna clear the screen to make sure that our screen is clear.
Now, we want to begin writing the program, so we have to create a file to
store our program, programs restored in files, and
then the compiler is run on that file.
So we're gonna do that by calling Notepad with the name of the file.
Now, let's spend this second and talk about how
Java programs are named; or how the files are named.
They have to begin with a capital letter and I will explain that
it a moment; and they also have to have a dot Java extension.
The compiler looks for that when you try to
compile the program, and without it, the program won't compile.
So, capital letter to start the filename and a java extension.
Now we're ready to open the file so just hit enter at this point.
And asks us if we want to create a new file, and we say yes.
The first thing we type is the words
public class and then the name of the file.
This is actually the name of a class
because every Java program is itself a class.
And notice that my class name is the same as
my file name including the capital letter, and that's very important.
Classes in Java have to begin with a capital letter.
The capital W in World is not that important, but I like to separate
my words with capital letters to make it easy to read a multi-word name.
So that's why I capitalize the W.
But the H has to be capitalized.
Drop down to the next line and type an opening brace.
The brace signifies that we're beginning the definition of the class.
We'll be talking a lot more about that.
And then indent at least three spaces or two spaces.
It doesn't really matter.
So like as long as you indent some.
Then type the words, public static void main open parentheses.
Capital S string open and close brackets and then the word args, just like that.
Public static void mainstream args.
Very quickly I'll explain why we do this.
The compiler is looking for a method called main.
The compiler looks for that as the place to begin compiling the program.
So every class at some point has to have a public
static void name or just a main method somewhere in it.
All our program is going to do is print hello world.
So we'll have the main method right here without anything else.
Underneath that, put an opening curly brace.
This brace signifies the beginning of what's called a block.
All methods have blocks.
The block is for the code that goes inside the method it's contained.
Drop down to the next line and indent
from there, and then type the word system.out.print.
Line ln not the whole word line, but we say
print line, cause it makes more sense than saying print loon.
It's hard to say.
Doesn't make any sense.
Open parenthesis, double quote.
Hello world.
Exclamation point.
Close double quote.
Close parenthesis and then a semi-colon.
Let me explain a little bit about what we are doing here.
We're wanting to print the phrase hello world to the screen.
The screen or the terminal or console is represented by system dot out.
And as we go through the course I'll explain more about what all that means.
We have to tell that object, if you want to think of it as an object, what to do.
And what we want to do is we want to print a line.
And the line we want to print is hello world.
And then we end that with a semicolon.
I'll be explaining all the syntax quite a bit as we go through the course.
We closed the block with a closing curly brace and
then we closed the class definition with another closing curly brace.
And that finishes up the program.
And that's all we have to write.
And again, it's Okay if you don't understand what
every single piece of this means, we'll be discussing it
a lot more throughout the course, but this is
what we have to have, to have a working program.
Before we end this lesson, let's save the file.
So, we're gonna click file saved make sure it's save and now we're finished
on the next video I'm gonna show you how to compile and run this program.