Compiling and Running a Program with Code Warrior

Translating Your Program

When your source program is entered and saved, it is time to translate it into the computer's machine language. In CodeWarrior, this can be done using the Project -> Make menu choice, or the keyboard shortcut Apple-m. When this is done, CodeWarrior displays a Building Mult.mcp sub window in which you can watch the translation as it proceeds through the compilation and linking stages. If all is well, the window should disappear returning you to where you were.

On the other hand, if your program contains typographical errors, CodeWarrior will display a Errors & Warnings window in which it will list the errors it discovered in your program. If you double-click on a given error, CodeWarrior will highlight the line in where that error was discovered. (Often, this is the line following the line where the error actually occurred.) CodeWarrior will not run a program that contains errors, so you must correct all errors in a program before proceeding.

To illustrate this, delete the final semicolon in the program. Then use Project -> Make to rebuild your program. When the Errors & Warnings window appears, double-click on the error.

The Errors & Warnings window lists the line where the error was discovered. Some times that may be after the actual line where the error occurred. Fix the error, rebuild your program, and then continue.

Running Your Program

Running your program is just as easy as anything else in CodeWarrior. Choose Project -> Run or use the keyboard shortcut Apple-r and the IDE will run the program for you. A window named Java Console will appear, in which your program will be executed.

When it prompts you for input, enter an easy-to-check number (like 15, 16 or 17) and verify that you get the correct results.


Printing a Hard Copy of Your Program

A paper copy of electronic information is called a hard copy. It is often useful to have a hard copy of one's source program, which is in the file As with much of CodeWarrior, this is quite easy: just make sure that is the active window and choose File -> Print, or use the keyboard shortcut Apple-p. A Printer dialog box should appear. You should just be able to click its Print button to print a hard copy of your program's output. If you must do anything beyond this (such as specify a printer), your instructor will inform you of the details.


Printing an Execution Trace

It is often useful to be able to print a hard copy of the output from your program, especially for more complicated programs. To do this use Edit -> Select All, or use the keyboard shortcut Apple-a to select all the output. Then use Edit -> Copy . Create a new text file and then do Edit -> Paste. All of your output should now be in the new file which you can print as normal.

Quitting Code Warrior.

Once you have a hard copy of your program's execution, you can tell your program to quit by choosing File -> Quit (or by typing Apple-q). A dialog window will then appear asking if you want to save any unsaved work. For example, with the temporary file that we just made to print the console window, we would click the Don't Save button.

To quit the Java Console, click on it and then do Apple-q.

Warning: If you recompile your program without quitting the Java Console first, you may get a compiler error telling you that the jar file could not be created.


Back to the Lab

Back to the Table of Contents

Back to the Introduction

Copyright 2000 by Prentice Hall. All rights reserved.