BLUE-J

advertisement
How To Run & Compile a Java Program Using
Blue J
Introduction
The purpose of these instructions is to provide you with the basic steps of running a
simple program code using Blue J a Java Compiler. A compiler such as Blue J will run
and execute your Java code, it will give you the results of your programming code.
These instructions provide the user with a step-by-step process and tips on overcoming
minute troubles. These instructions are specifically designed to be used with a computer
in the DePaul labs.
Equipment & Materials


Microsoft 98 or higher PC
Blue J Software Package
Step-By-Step Procedure
STEP 1: Turning Your Computer ON



Make sure you turn on your computer properly, if it has been turned on for a
while, reboot to avoid any complications.
To reboot click on Start button located on the left hand corner of the screen.
Click Shut Down.
The Shut Down Window will show up, click on Restart and then OK.
STEP 2: Locating Blue J
Click on the Start button, locate Courseware Applications, should be at the top of the
menu, (Look at Figure 1.1).
 Click on Courseware Applications.
 Click on Installed apps for CSC.
 Click on Blue J. This will open up a black window and then the Blue J program.
1
Blue J
Figure 1.1
STEP 3: Creating a New Project
You should have a gray screen on your Desktop with the title Blue J on the title bar.
(Look at Figure 1.2).
 To create a new Class click on Project from the tool bar and then scroll down to
New Project and click. This Class will contain your code and you will be able to
call it up by the name you give it.
 A New Project box will open, prompting for your file name.
 Locate your cursor in the file name box and give your file a name.
 For the purpose of this project, name it Project1.
 Click on Create. This will create a file where you can include several classes.
Look for A:\
File name: Project1
Figure 1.2
STEP 4: Naming Your Class
You should be looking at the same window as in STEP 3, but with a white screen. In
these steps you will be naming and creating the class.
2




Click on the New Class button. You will get a Create New Class Window.
Give your class a name.
No spaces within words.
Name your class PianoKeys. (no spaces)
STEP 5: Opening Your Class
You have created a class.
 Right click on the class. You will get a list.
 Click on Open Editor.
 On your keyboard press the Ctrl and A keys simultaneously and then press the
Delete key. This should delete the default code in the window.
STEP 6: Inserting Programming Code
Know you can insert the code found on page 6 so that Blue J can compile it.
Figure 1.3
STEP 7: Compiling Program
You are now ready to compile if you run through any problems look at the TIP
section on page 5.
 Under the toolbar you have buttons, click on compile.
 Look at the box at the bottom of the screen if it states “Class compiled-no syntax
errors.”
 Click on class located in toolbar.
 Click on Close. This will take you back to the main screen as in Figure 1.4, so that
you can then run/compile your code.
3
STEP 8: Getting the Program Results
You are back on the main screen in Blue J. (Look at Figure 1.4).
 Locate the Piano Keys class and right click .
 Click on void main (args). This will execute your code.
 You are know in a Window called Method Call click OK.
 You should get a Terminal Window with the results of the program. Which are: A
piano has 88 keys.
Click to run
program
Figure 1.4
STEP 9: Clearing & Closing Terminal Window
To clear and close the Terminal Window.
 Click on Options on the Toolbar.
 Click on Clear.
 Click on Options on the Toolbar.
 Click on Close.
4
STEP 10: Proper Way to Exit Blue J
You should be on the main screen in Blue J, (Look at Figure 1.5).
 On the Tool Bar click Project.
 Scroll down and click on Quit.
Click on Project
Scroll Down
Click on Quit
Figure 1.5
Conclusion
By following these 10 simple steps you should be able to get any Java code, place it into
the Blue J compiler, compile it and get the results from your code. You are know
familiar with the basic steps needed to run Java code with Blue J, these are Open the
program, create a Project, Save the Project, Create a Class, Insert Code, and Execute the
Program.
5
Tips & Troubleshooting Procedures
Compiling & Error Messages
If you receive a ‘;’ expected error message, Blue J will highlight the line that contains the
error.
Blue J will sometimes give you an error message, and you will have to figure out what
the syntax error is.
Examples:
 Included a space within a word that shouldn’t be there.
 Forgot a quotation mark
 Forgot a dot
Saving to the A: drive
Click on the Look in dialog box and choose the A:\ drive (3 ½ floppy disk ). This is up to
the user. You can locate your file easily. Another option is saving to desktop.
Programming Code
//PianoKeys.java
//Demonstrates the declaration, initialization, and use of an integer variable.
public class PianoKeys
{
//************************************************
//Prints the number of keys on a piano.
//************************************************
public static void main (String [] args)
{
int keys=88;
System.out.println ("A piano has "+keys+" keys.");
}
}
6
Download