Using CodeWarrior
Creating a HelloWorld.java program
This example is intended to get you started with CodeWarrior. This
example assumes that you are working from CDF-PC on campus; if you
are working from home, you'll probably want to use C: instead of H:
for the hard drive. The instructions for invoking CodeWarrior
are also different if you're working from home.
This document contains details about how to create a Java program from
scratch, or how you can include existing Java files (files that have
already been created and exist on your hard drive). All steps are the
same for these two tasks, except for step 4. Step 4 (a) explains how
to create a new Java program, and step 4 (b) explains how to include
existing Java program files. In this example, we assume that the Java
program will be contained in a single Java file called
HelloWorld.java. We will also name our project HelloWorld.
- Invoke CodeWarrior
- If working from CDF-PC, double click on the "Applications" folder
which will be showing on your desktop, and then double click on the
"CodeWarrior" icon.
- If working from home, select Start -> Programs -> CodeWarrior Pro 5
-> CodeWarrior IDE
- Create a new project
- To open a new project, select File -> New...
- Click on Java Stationary
- Project name: HelloWorld
(We are using the name of the class containing the main method.
Alternatively, we could use the name of the folder where
your files are stored.)
- Location: H:\java\HelloWorld
(Choose a folder/directory that you have write permission on.
Your files for this program will go here. If the "java" folder
does not already exist in your H: drive, you will need to click
on "Set...". This will bring up a "Create New Project..."
window. Change "save in:" to H: and then click on the yellow
Create New Folder icon and type in "java" and then click "Open"
and then click "Save."), and then click OK.
[Notice that whatever name you choose for Project name will
always be the last part of your Location.]
[Note that we could have simply used a Location name of
H:\HelloWorld. Having the "java" directory, however, helps to
organize things better on your harddrive. This is especially
helpful if you are working from home and have several other
folders already on your hard drive.]
- Click on the "+" next to Java2 to open it up, and then select Csc
1.0, and click on OK. This will bring up a HelloWorld.mcp window.
- Tell Java where main method is
- Select Edit -> Java Application Settings...
- Click on Java Target (under the Target settings)
- Main Class: HelloWorld
(change TypeYourMainClassHere to be the name of your class
containing the main method).
- Click on Save, and then close the window by clicking the "x".
- Include Files - create or open Java files
- Click on Sources in the HelloWorld.mcp window to highlight it.
This ensures that the file you add or create will be put into the
Sources folder.
- (a) Create new Java file
- (b) Add existing Java file
- Use Windows Explorer to copy the files from your Handouts
directory (or from wherever) into directory H:\java\HelloWorld.
More details about using Explorer are provided in the section
at the end of this document.
- For both part (a) and (b)...
With Sources still highlighted, click Project -> Add Files... and
select the HelloWorld.java file in the H:\java\HelloWorld directory.
(If desired, more than one file could be selected by holding the CTRL
key and left clicking each file).
- The HelloWorld.java file will automatically be added to Sources
in your HelloWorld.mcp window. If you don't see it there, click on
the various tabs in this window (Files, Link Order, Targets) to cause
it to refresh.
- Click on the "+" next to Sources, and you will see the files that
are part of this program. Double click on your ".java" file to bring
up a window that will allow you to view or edit it.
- Compile
- Select Project -> Make. Any compile errors will come up at this
time. They will indicate the line number that has a problem.
- Run
- Select Project -> Run. The output will come up in an MS-DOS
window. Any input for the program would be entered here. Press Enter
in this window when the program has finished.
- Closing CodeWarrior
- Select File-> Exit to leave CodeWarrior. Your project will be saved.
- Reopening a Project
- Suppose you want to modify the HelloWorld project the next time
you use CodeWarrior. You would start up CodeWarrior as outlined in
step 1, and then you would select File -> Open... An Open window will
pop up. You will change the directory in this window until you get to
H:\java\HelloWorld, and then you will open the HelloWorld.mcp file.
It stores all the information about your project.
- Another way of reopening a project is to locate the project's
HelloWorld.mcp file from within Explorer, and then you can double
click on it. This will start up CodeWarrior, and take you might into
that project.
Using Windows Explorer
In step 4 (b) it talks about using Windows Explorer to copy files
from one directory to another on your computer. It should be
noted that this application is not part of CodeWarrior. You
can minimize your CodeWarrior application (by clicking on the minus
sign at the top right corner of CodeWarrior), and then start up
and run a Windows Explorer session as follows:
Invoke Explorer
- Right click on Start -> Explore...
The environment
- On the left side of the window you can click to open up drives
(such as A: or H:), and folders (indicated by a yellow icon.
- On the right side it will always show the files and folders
that are in the folder that has been selected (by double
clicking) in the right side of the window.
Create a New Folder
- Suppose you wanted to create a folder called H:\java
where you could store all your Java Projects. This could be
done from within CodeWarrior, as explained above, or you could
do it right here in Explorer.
- On the left side of the Explorer window, you would double click
on H: to open the H: drive.
- Then you would select File -> New -> Folder from the
menu, and type in java for the filename.
Copying files
- Suppose you wanted to copy the AssignmentA.java file from your
H:\Handouts\AsstA folder into your
H:\java\AssignmentA folder.
- On the left side of your Explorer window you would double
click on H:, and then double click on Handouts, and then double
click on AsstA. At this point, you will see AssignmentA.java
on the right side of the Explorer window.
- Single click on AssignmentA.java which is showing
on the right side of the window. Then select Edit -> Copy.
- Now on the left side of your Explorer window you will change
the folder to the folder where you want to place this file.
Double click on H:, then double click on java, and then double
click on AssignmentA. Then select Edit -> Paste, and
the file will appear in this folder.
- Now you can close Explorer (click on the "x" in the top right
corner) and go back to CodeWarrior and you can then bring this
file into your CodeWarrior project. If you minimized CodeWarrior
before starting up Explorer, you can bring it back to full size
by clicking on "Metrowerks CodeWarrior" which will be showing
along the bottom of your screen.