Sams Teach Yourself Java 2 in 24 Hours

Sams Teach Yourself Java 2 in 24 Hours

By Rogers Cadenhead

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 Software 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, you don't include the file extension .class in the command.

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.

Share ThisShare This

Informit Network