Java Reference
In-Depth Information
Notepad will create an unnamed file and display a blank window indicating that the file is empty. Commands are
entered by positioning the cursor and typing. The first command we want to enter is the path command.
2.
Type
path=f:\jre\bin
(see Figure
A-17
).
This will set the path to the bin folder that contains the JRE commands. The
java
command is needed to run the
employee application in the JRE and is stored in the bin subfolder. (If you need proof, use My Computer to display the
contents of the bin folder. You will see an “application” file called java. This program is run when the
java
command
is issued.)
3.
Press Enter to add a new line.
4.
On the new line, type
Set classpath=f:\
This statement defines the classpath variable, which, essentially, tells Windows where to find our application
classes (i.e., the package folders myFirstPackage). There must be at least one space between
Set
and
classpath
,
and there are no other spaces in the command. Be careful: this must be coded exactly as shown. Common mistakes
include using forward slashes instead of the back slashes, using colons for semicolons (and vice versa), and having an
extra space at the end of a line.
5.
Press Enter to add a new line.
6.
On the new line, type
java myFirstPackage/EmployeeApp
There must be at least one space after the
java
command and no spaces thereafter. When this command
is encountered, Windows finds the
java
program (because of the
path
statement) and passes the name of our
application (
myFirstPackage/EmployeeApp
) to the
java
program. Notice that when identifying the application both
the package and class file names are needed and are separated by a forward slash. The
java
program then passes the
bytecode (i.e., the class file) to the Java interpreter (i.e., the JVM) for translation into machine language and execution.
The final code should look like Figure
A-18
.
Figure A-18.