Java Hello World Source Code
Filename:
HelloWorld.java
Source Code:
class HelloWorld
/*States that the name of the class is
Hello World*/
{//begin class
public static void main(String args[])
/*Creates a "method" (collection of code)
called main, main runs automatically when
a class is run*/
{//begin main method
System.out.println("Hello World");
}//end main method
}//end class
Notes:
This program has to be compiled and run by a Java Compiler, available at
http://www.sun.com/ . Java is case
sensitive and therefore the filename must be the exact same case and name as the
class name. If you use Sun's Java SDK for Windows and compile and run from
a DOS prompt the command to compile this program is:
javac HelloWorld.java
That will create a compiled file named HelloWorld.class, you then run the command:
java HelloWorld
And it will display this text:
Hello World
For these commands to work in this format you must be in the "bin" directory (installed by the SDK), and have javac.exe, java.exe, and HelloWorld.java all in that directory.