Metrowerks Codewarrior is an integrated development environment (IDE) for Java, C++, and other languages. It combines software resources for editing, compiling and running programs. In this IDE Java programs consist of two parts:
The Codewarrior project combines precompiled code from the Java class libraries with the code compiled from your Java source program, thereby increasing the functionality of your code. This lab will take you through the steps required to edit, compile, and run Java programs.
- the Java code itself, which contains the text of your source program and
- a project, which contains the Java bytecode that will be executed when you run your program.
Close all applications that may be running on your computer in order to make as much memory as possible available to Codewarrior.
Codewarrior IDE 4.0 is located in the Lab Applications folder.
NOTE: Remember how to find this program because you're going to need it every week.
Once you have Codewarrior running, create a new project and configure it according to the following directions:Click on the FILE menu option, then select NEW. Make sure the PROJECT tab is selected and enter the name of your project, "Lab1". The "Location" text box should indicate that your project will be stored on the desktop. In the project text area, double click on "JAVA Stationery". During this step, you should see something like the following window:
![]()
In the New Project window, click the "+" sign which is to the left of Java2. Select "Java Application" as the project type. During this step, you should see the following window:
![]()
After you save your project, Metrowerks will open a project window that should look something like this:
![]()
If this is NOT how your project looks, ask for help.
To compile and run TrivialApplication.java choose the Run option from the Project menu. Codewarrior will compile the application into Java bytecode and then interpret the bytecode all in one step. As a result, something like the following Java Output window should appear on your desktop.
![]()
Java programs are run by the Metrowerks Java program, which is an implementation of the Java Virtual Machine. It's a good idea to remove the Java Output window when the program is finished running. To do so, click on the "go-away box" (Upper left corner of the window's title bar).
public class TrivialApplication {
public static void main(String args[]) {
System.out.println( "Hello World!" );
}
}
To Do: Change "Hello World!" to some other message by editing the
System.out.println() statement on line 3. Then re-run the program.
Codewarrior will automatically save your changes.
To Do: Change the name of the class in TrivialApplication.java to HelloWorld and then save the file and try to re-run the program.
System Error:A system error will occur when Codewarrior tries to load the TrivialApplication class into memory but can't find it. This time you should get an error message in the Java Output window which says:
You can fix this error by changing the class' name back to TrivialApplication (spelled EXACTLY that way) and then saving and re-running the program.Can't find class TrivialApplication
NOTE: If a Java program's file name does not match the name of the public class that is defined within the file, it won't run properly.
To do: Delete the semicolon after the System.out.println() statement and then re-run the program.
Syntax Error:This time you should get an error message in the Errors and Warning window which says:
Error: ';' expected
TrivialApplication.java line 6 System.out.println("Hello World")