Java Reference
In-Depth Information
Figure 4.1
Use javac to compile the Employee class.
Be sure to save the EmployeeDemo class as c:\payroll\EmployeeDemo
.java. (It needs to be in the same folder as the Employee class.)
Step 4: Compile the EmployeeDemo class
Assuming that Employee.java and EmployeeDemo.java are in the same folder,
go back to your command prompt and compile the EmployeeDemo class.
Look at the contents of the c:\payroll folder. You should now have four files in
there: the source code and bytecode for Employee and the source code and
bytecode for EmployeeDemo.
In Chapter 7, “Advanced Java Language Concepts,” the CLASSPATH
environment variable will be discussed. Until then, if you are writing a
Java program that consists of more than one class, the bytecode for each
class must appear in the same folder on your hard drive. Otherwise, your
dependent classes will not compile. For example, EmployeeDemo will
compile only if the compiler can find the Employee.class file because the
EmployeeDemo class uses (and therefore is dependent on) the Employee
class.
Step 5: Run the EmployeeDemo program
After both classes are written and compiled, you can run the EmployeeDemo
program. Figure 4.2 shows the output.
Figure 4.2
Output of the EmployeeDemo program.
Search WWH ::




Custom Search