Structured Programming   «Prev  Next»

Java HelloWorld Unix - Exercise

The Java interpreter

Run the HelloWorld program (Unix)

Objective: Run the HelloWorld program.

Scoring

This exercise is not scored. It's an opportunity for you to check your understanding of the material covered in the preceding lesson. When you're finished, click the Submit button to receive credit for having completed it.

Background | Overview

In this exercise you will run the HelloWorld program that you compiled earlier. This is simply a matter of issuing a single command to invoke the Java interpreter.

Instructions

  1. From the shell window navigate to your progfun directory.
  2. The command to run the Java interpreter is java. Run your program using the Java interpreter by issuing the following command at the command prompt.
    java HelloWorld
    

If you receive the error:
Exception in thread "main" java.lang.NoClassDefFoundError:
HelloWorld

this indicates that the Java interpreter can't find your class file. This problem usually arises when your CLASSPATH environment variable is set incorrectly. Roughly speaking, the CLASSPATH environment variable is used to notify SDK tools where to find class files. For this course it is recommended that your CLASSPATH environment variable be unset, in which case the SDK tools will use a default CLASSPATH that always includes the current directory. Try unsetting your CLASSPATH by using the command:

unset CLASSPATH

and running the application again. Double check to make sure that you are not specifying the .class extension of your class file when issuing the java command. If you're still having difficulty, please contact your tutor, and in your email include any error messages you are observing.