Hello World

This simple class is one of the most basic java programs. It will simply display "Hello World" to the console. You won't need to understand everything about this program just yet. As you progress throughout the tutorials you will gain a better understanding on the how the Java language is structured.



Open the command prompt (CMD - see the Getting Started ) and type in the following commands.

C:\Windows\System32>cd \
C:\>md Java
C:\>cd Java
C:\Java>
C:\Java>md helloworld
C:\Java>cd helloworld
C:\Java\helloworld>Notepad HelloWorld.java


Copy and Paste, or type the following code into Notepad and be sure to save the file when you are done. Java is a case sensitive language so be extra careful when it comes to upper and lower case letters.


class HelloWorld {
	public static void main(String args[]) {
		System.out.println("Hello World!");
	}
}


Now switch back to the command prompt (CMD) and type in javac HelloWorld.java and press Enter.
Now type in java HelloWorld and press Enter.
As long as you typed in everything properly you should see Hello World! displayed to the console.
Congratulations you have created and executed your first Java program!


C:\Java\helloworld>javac HelloWorld.java
C:\Java\helloworld>java HelloWorld
Hello World!


You may have noticed that the name of the file, HelloWorld.java, is identical to the name of the class without the extension. Java convention dictates that the file name should match the name of the class. The javac compiler requires that the source code file extension must be .java. The HelloWorld.java source file is officially known as a compilation unit.


Tutorials