Java Reference
In-Depth Information
FIGURE A.10
Compiling a Java
program in a com-
mand-line window.
A
If the program compiled without any errors, a file called
HelloUser.class
is created in
the same folder that contains
HelloUser.java
.
The class file contains the Java bytecode that will be executed by a Java interpreter. If
you get any errors, go back to your original source file and make sure that you typed it
exactly as it appears in Listing A.1.
After you have a class file, you can run that file using a Java interpreter. The kit's inter-
preter is called
java
, and it also is run from the command line.
Run the
HelloUser
program by switching to the folder containing
HelloUser.class
and
entering the following:
java HelloUser
You will see the text “Hello” followed by a space and your username.
NOTE
When running a Java class with the kit's Java interpreter, don't
specify the
.class
file extension after the name of the class. If
you do, you'll see an error such as the following:
Exception in thread “main” java.lang.
➥
NoClassDefFoundError: HelloUser/class
Figure A.11 shows the successful output of the
HelloUser
application along with the
commands used to get to that point.
If you can compile the program and run it successfully, your kit is working and you are
ready to start Day 1 of this topic.