The Hello World Application

class HelloWorld {

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

Hello World is very close to the simplest program imaginable. When you successfully compile and run it, it prints the words "Hello World!" on your display. Although it doesn't teach very much programming, it gives you a chance to learn the mechanics of typing and compiling code. The goal of this program is not to learn how to print words to the terminal. It's to learn how to type, save and compile a program. This is often a non-trivial procedure, and there are a lot of things that can go wrong even if your source code is correct.

To write the code you need a text editor. You can use any text editor like Notepad, Brief, emacs or vi. Personally I use BBEdit on the Mac and TextPad on Windows.

You should not use a word processor like Microsoft Word or WordPerfect since these save their files in a proprietary format and not in pure ASCII text. If you absolutely must use one of these, be sure to tell it to save your files as pure text. Generally this will require using Save As... rather than Save. If you have an integrated development environment like BlueJ 1.0 or Borland JBuilder, that will include a text editor you can use to edit Java source code. It will probably change your words various colors and styles for no apparent reason. Don't worry about this yet. As long as the text is correct you'll be fine.

When you've chosen your text editor, type or copy the above program into a new file. For now type it exactly as it appears here. Like C and unlike Fortran, Java is case sensitive so System.out.println is not the same as system.out.println. CLASS is not the same as class, and so on.

However, white space is not significant except inside string literals. The exact number of spaces or tabs you use doesn't matter.

Save this code in a file called Use exactly that name including case. Congratulations! You've written your first Java program.

Previous | Next | Top | Cafe au Lait

Copyright 1997-2006 Elliotte Rusty Harold
Last Modified August 30, 1999