An Introduction to CodeWarrior for CS111

CodeWarrior is the program we will be using to edit and compile our Java programs. Java programs are written in files which end with .java. CodeWarrior requires Java programs to be organized into projects. For the first few assignments in CS111, we will create the project files for you. You will be able to identify the project files by the .mcp extension (stands for Metroworks CodeWarrior Project) and the Code Warrior project file icon shown below.
Note the difference from a .java file icon below:

Applications and applets

There are two kinds of Java programs:

Running Java applications in CodeWarrior

  1. To start CodeWarrior, open the folder you have downloaded. Find the Code Warrior project (i.e. .mcp) file and double-click it to open it up. Do NOT open (by double-clicking) the .java files directly!

  2. The project file window appears. You must keep this window open while working on your programs. You can resize the window by pulling on its down right corner.

    Note that the window has 3 tabs: Files, which shows you the files included in the project, Link Order, which allows you to specify the order of compilation of your files, and Targets. In this lab you will only be using Files.

  3. Since this project already has working code in it, we can try to run it. There are several alternative ways of doing it: No matter which way you run the program, you will see a wide window appear on your screen, and the program result will be displayed in it. The window is Java Console.

    In the right upper corner of the screen, where the active application is shown, you will see MRJApplication.

  4. Before you can run your application again, you need to quit MRJApplication. If MRJApplication is active, i.e. its name and icon are displayed in the right upper corner of the screen, click on the little apple in the left upper corner of the screen, hold the mouse button down, and select Quit from the menu:

    If MRJApplication is not shown in the right upper corner, but the MRJApplication icon in the project folder is dark, select the MRJApplication from the active programs menu (in the right upper corner):

    Now you can quit it, as explained above.

    After you quit the MRJApplication, you can run the program again.

  5. Of course, you will not be just running the same program over and over, you will be changing it to make it do other, more intersting things. Java code is written in text files, and to change it, you use a text editor.

    If you want to change a file, say Sentence.java, double-click on it. The text editor called SImple Text will open the file.

    Type inm your changes, then choose save from the file menu or press Apple-S.

    In the project window you will see a red checkmark next to the file name Sentence.java: an indication that the file has changed, and the program needs to be recompiled.

  6. Now you need to recompile your program and run it again. The command in the Project menu that allows you to recompile and reassemble the program is Make. There is also Bring Up To Date command that recompiles the project if needed.

    However, the Run command and the forward arrow in the project window automatically recompile the project if needed. They also automatically save all the files in the project that have been modified, so usually you will only need to press the forward arrow if you have changed the files.

    If all goes well, your program will recompile successfully and run. But what happens if there is a mistake in the code? The program will not compile, and a window pop up displaying error messages:

    You can correct the error right in that window or close the error message window and correct it in the original file, the result will be the same. After you have corrected the error, try to run the program again. Note that Java error messages sometimes may not point to the exact spot where the error has occurred. If it's not clear what the error is, carefully check all your code. Understanding error messages is one of the most difficult skills that you will acquire during this course.

    Note that not closing an MRJApplication before recompiling the program will also cause an error message, so check (by clicking on the active program list in the right upper corner) if an old MRJApplication is still running. If it is, quit it as described above, and then recompile the program

    There may be a different kind of an error in your program when the each piece of the program has compiled correctly, but the program cannot be assembled together. In this case you might see an alert window:

    The most likely cause is a misspelled class name. Click on OK and carefully check your code.

When you are done

When you are done working on the project, you must quit CodeWarrior (choose Quit from the File menu). There may be only 20 CodeWarrior programs running on Science Center computers at the same time, so please be considerate of others and quit it if you are not using it.

Don't forget to save your files on a zip disk or upload them to your private folder (see instructions for Fetch).

Please delete your folder on the machine that you were using: drag it to the trash and empty the trash. It is your responsibility not to leave your work behind for other students to see.