CIT 591 Doing without BlueJ
David Matuszek

Creating and running a Java program requires a lot of what we call "bookkeeping"--managing a lot of fiddly details. BlueJ does a lot of the bookkeeping for you, and if you can possibly get it running, you should. If not now, soon.

Having said that, here's how to do the bookkeeping yourself:

Editing the program

You can use any text editor to create and edit the program. Microsoft Word can be made to work, if you save the file as Text Only. I recommend an editor called jEdit, from: http://www.jedit.org/ (it requires Java to run, but you need that anyway).

Avoid using tabs in your programs--use spaces to indent things properly. Java won't mind, but tabs aren't the same width everywhere, and sooner or later your nice indentation will be destroyed. (BlueJ automatically converts your tabs to safe, reliable spaces.)

If the name of your class is Drawing, then the file you save it on must be named Drawing.java. No other name will do. Capitalization must be correct. Each time you edit, depending on the editor you use, you may have to change the extension from .txt (or .java.txt) back to .java.

Compiling the program

You have to compile the program before you run it. You do this from the command line.

UNIX: You are already at the command line. Type javac and hit Return; if you get a long message from Java, then it is installed correctly. If you get a short error message, it isn't. Compile your program by typing javac Drawing.java (assuming Drawing.java is the name of your text file). Correct capitalization is essential! This will produce one or more files with the .class extension.

Windows: If you have an MS-DOS icon, double-click it. Otherwise, choose Start -> Run... and type in the word cmd (and hit Enter). Type javac and hit Enter; if you get a long message from Java, then it is installed correctly. If you get a short error message, it isn't, but you can probably still use it; find the file javac.exe and write down the full path to that file. Navigate to the folder containing your program and type either javac Drawing.java (assuming Drawing.java is the name of your text file) or, if necessary, use the full path and name, such as jdk1.3.1_01\bin\javac Drawing.java (correct capitalization is not essential, but it's a good habit). This will produce one or more files with the .class extension.

Running an application

If your program is an application, and it has been compiled onto a file named Drawing.class, you can run the program by navigating to the folder containing the file, typing java Drawing and hitting Enter. Correct capitalization is essential, even on a Windows computer. Do not type the .class extension.

If Java isn't installed correctly, you may still be able to run your program. Find the full path name to the java.exe file and use that path name (as you did to compile the program).

Creating an HTML file (Applets only)

If your program is an applet, you need to create an HTML file. Use this as a model:

<html>
<head>
  <title>My Applet</title>
</head>
<body>
  <applet code="Drawing.class" height="250" width="400">
  </applet>
</body>
</html>

You can give this file any name you like, but it should have the .html extension. Let's call the file draw.html. Put the file in the same directory (folder) as the .class file to which it refers.

You can change the height and width of the applet window by changing the numbers in this file. You need to give the full name of the class file, with correct capitalization. The best way to create this file is by copying and pasting (so you minimize the number of typing errors), then changing only the parts that need to be changed.

Running an applet

You run the applet indirectly, by using the HTML page that refers to the applet. You must use the HTML page; you cannot run the applet without it.

From Internet Explorer, choose File -> Open... -> Browse... and navigate to the HTML file and open it.

From Netscape, choose File -> Open Page... -> Choose File... and navigate to the HTML file and open it.

But the best way (if it works) is to use the command line to type appletviewer draw.html and hit Enter. If this doesn't work, you can use the same tricks as above to find and run the appletviewer.exe file. Another trick is to copy appletviewer.exe to the same directory (folder) as your program, then run appletviewer from that folder.