Hello World

This simple class is one of the most basic java programs. It will simply display "Hello World" to the console.



C:\Windows\System32>cd \
C:\>md Java
C:\>cd Java
C:\Java>
C:\Java>md helloworld
C:\Java>cd helloworld
C:\Java\helloworld>Notepad FirstProgram.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("First Java Program");
	}
}


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 FirstProgram.java
C:\Java\helloworld>java A
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