Exercise 1: Writing, Compiling, and Testing A Basic Program
Exercise 1: Writing, Compiling, and Testing A Basic Program
Program
The objective of this exercise is for you to become familiar with the steps necessary to
write (or modify), compile, and test (execute) your Java technology programs.
2. Open an editor, and enter in the Java technology syntax for the Shirt class
shown earlier in this module (the program source code).
4. Open an editor, and enter the ShirtTest class shown earlier in this module
(the program test file source code).
7. Type the following command to compile the program into an executable bytecode
file.
javac Shirt.java
8. Type the following on the command line to compile the program into an
executable bytecode file.
javac ShirtTest.java
java ShirtTest
11. Change the value of the price variable to 14.99 and the shirtID to
112244.
javac Shirt.java
java ShirtTest
System.out.println(quote);
}
}
Note – Be sure to indent as shown; it makes the program much easier to read and
easier to debug.
17. Enter the following in the terminal window to compile the program:
javac QuotationTest.java
18. If no error messages appear, enter the following in the terminal window to run the
program:
java QuotationTest
19. Open the Quotation.java file again, and change the “Welcome toSun!”
text to your own favorite quotation. Be sure to leave the quotation marks at the
beginning and the end.
Shirt.java
public class Shirt {
ShirtTest.java
public class ShirtTest {
myShirt.displayShirtInformation();
}
}