______________________________________________________________________________________
Hello, Java World!
The way to make a hello world program in java is fairly simple. Let me walk you through it.
First, we state the name of the class:
- Code:
-
class HelloThar{
This tells the compiler that the class HelloThar starts there. If you are unsure what this whole class thing is, just think of it like a blue print of a object, with all information about it.
Then we give the code a main, just like in many languages:
- Code:
-
public static void main(String[] args) {
There is a lot of gibberish in there, of which I will explain in a different tutorial. Just know that that lines starts the method main of the HelloThar class. If you do not know, a main is just what you probably can think of what it is; Everything being put into one place in a program.
Now we tell it to print, using the System.out class method println:
- Code:
-
System.out.println("Hello, World!");
Always end a method call with a semi colon. If you are wondering about all those dots, it is because we are calling the System.out class so that we can use it to print. There is ways you can get around typing that whole line, but we will get into that later.
Finally end all your wrappings: first your main, then your class.
- Code:
-
}
}
Now you have your first ever Java program, a simple hello world!