Hello World: The Application
At least since the first edition of Kernighan and Ritchie’s The C Programming Language it’s been customary to begin programming tutorials and classes with the “Hello World” program, a program that prints the string “Hello World” to the display. Being heavily influenced by Kernighan and Ritchie and not ones to defy tradition we begin similarly.
The following is the Hello World Application as written in Java. Type it into a text file or copy it out of your web browser, and save it as a file named HelloWorld.java.
class HelloWorld {
public static void main (String args[]) {
System.out.println("Hello World!");
}
}
To compile this program make sure you’re in the same directory HelloWorld.java is in and type javac HelloWorld.java at the command prompt. Hello World is very close to the simplest program imaginable. Although it doesn’t teach very much from a programming standpoint, it gives you a chance to learn the mechanics of writing and compiling code. If you’re like me your first effort won’t compile, especially if you typed it in from scratch rather than copying and pasting. Here are a few common mistakes:
System.out.println("Hello World")
?class
is not the same as Class
for example.Congratulations! You’ve just written your first Java program!