Previous Section  < Day Day Up >  Next Section

Workshop: Running a Java Program

To run the Java program you have just created, you must use a Java interpreter such as java, the command-line tool included with the Java Development Kit. An interpreter makes the computer follow the instructions you gave it when you wrote the program.

To run a Java program, the command java is followed by a space and the name of the class file that contains the program. Although the class file's name includes the .class extension, this part of the name must be left off when running the program with the Java interpreter.

To see whether the Saluton program does what you want, run the class. If you're using the kit, go to the folder that contains the Saluton.class file and type the following at a command line:


java Saluton


Even though the program's filename is Saluton.class, don't include the file extension .class in the command, or the interpreter will fail with an error.

When the program runs, it should state the following:


Saluton mondo!


If you see this text, you have just written your first working Java program. Your computer has just greeted the world, a tradition in the field of computer programming that's as important to many of us as caffeine, short-sleeved dress shirts, and the Star Wars films.

By the Way

You may be asking yourself why "Saluton mondo!" is a traditional greeting, especially if you have tried using it in a conversation with other programmers and received funny looks in response. It's the phrase "Hello world!" in Esperanto, an artificial language created by Ludwig Zamenhof in 1887 to facilitate international communication. The author uses it here in the hope that more computers will be inspired to learn Esperanto.


    Previous Section  < Day Day Up >  Next Section