Java Reference
In-Depth Information
Step 1: Write and Save the Source Code for Vehicle
Begin by writing the following Vehicle class, declaring it in a package named
com.wiley.trans. Type in the class, but do not save it yet.
package com.wiley.trans;
public class Vehicle
{
public String make, model;
public int year;
public double purchasePrice;
public Vehicle(String make, String model, int year)
{
System.out.println(“Constructing Vehicle”);
this.make = make;
this.model = model;
this.year = year;
}
public double sellVehicle(double sellPrice)
{
System.out.println(“Selling “ + this.toString());
return purchasePrice - sellPrice;
}
public String toString()
{
return year + “ “ + make + “ “ + model;
}
}
Save the Vehicle.java file in a directory you create named c:\src (src is short
for source code).
Step 2: Compile the Source Code Using the -d Flag
Before you compile Vehicle.java, create a folder on your hard drive named
c:\my_bytecode.
The -d flag allows you to specify an output directory for the bytecode;
however, for the -d flag to work successfully, the output directory must
already exist.
Open a DOS window and use the cd command to change directories into the
c:\src directory you created in the previous step. To compile Vehicle.java, use
the -d flag of javac, specifying the output directory as c:\my_bytecode. The
command to enter follows.:
javac -d c:\my_bytecode Vehicle.java
Search WWH ::




Custom Search