Compiling and Running a Program with JBuilder

Translating Your Program

When your source program is entered and saved, it is time to translate it into the computer's machine language. In JBuilder, this can be done using the Project -> Make project "Mult.jpg" menu choice. When this is done, JBuilder will display any errors that it finds in the lower window.

If you double-click on a given error, JBuilder will highlight the line in where that error was discovered. (Often, this is the line following the line where the error actually occurred.) JBuilder 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 project "Mult.jpg" to rebuild your program. Double-click on the resulting error. Fix the error, rebuild your program, and then continue.

Selecting the Class to Run

There may be many classes inside our project, some of which may have a main function. We need to let JBuilder know which of these classes is the one we should run. Choose Run -> properties . In the resulting window you should see a text area labeled Main Class:. Click on the Set button next to it and then select Mult. Now when you tell it to run the project, it will run the code held in the main function of Mult.

Running Your Program

Running your program is just as easy as anything else in JBuilder. Choose Run -> Run Project and JBuilder will run the program for you. It will execute in the window towards the bottom of the screen.

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 JBuilder, this is quite easy: just make sure that is the active window and choose File -> Print. 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 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 JBuilder.

Once you have a hard copy of your program's execution, you can tell your program to quit by choosing File -> Quit or clicking on the close box for JBuilder. 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.


Back to the Lab

Back to the Table of Contents

Back to the Introduction

Copyright 2000 by Prentice Hall. All rights reserved.