Tutorial 1 Summary
In tutorial 1, we cover how to make a simple "Hello World!" program. In Java, every compiled non-applet program starts running in the "main()" function (or method, which is the more correct Java term). We write the main method as follows:
public static void main(String[] args) {
// stuff you want the program to do
}
The line that begins with the double forward slash "//" is called a comment, which allows you to put non-code in your Java code. Basically it just lets you say stuff you want yourself or other programmers to see, but you want Java to ignore.
The main building blocks of Java are classes, which we will cover in more detail later. For now, just know that your file must be structured something like the following:
public class HelloWorld {
// stuff to put in the class, like the main method
public static void main(String[] args) {
// stuff you want the program to do
}
}
Everything you put inside the main method will execute line-by-line, starting from the top. To print something out to the console (where we see the output of the program), you use:
System.out.println();
System.out.println() is a function that prints text out to
the screen. You put whatever you want printed out inside the
parentheses, and surrounded by double quotes. Therefore if you want
to print "Hello World!" to the screen, you say:
System.out.println("Hello World!");
Our completed "Hello World" program looks like this:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
You must save the file as HelloWorld.java, and if you're using Eclipse, everything else will be taken care of. If not, you need to compile the program using "javac", the Java compiler. You do this by running "javac HelloWorld.java". Once that is done, you run the program with "java HelloWorld".

