Exposure Java with BlueJ
Exposure Java likes to teach you Java with teeny-tiny files to demonstrate an idea. Most IDE's are designed for when you are making a project with multiple classes that work together. For that reason, Professor Schram likes JCreator LE, which integrates a text editor with 1 button for compiling, and 1 button for executing the bytecode. But what if you run Linux, Irix, OSX, Solaris, etc.? There is no JCreator for any other platform but Windows. Fortunately, there are many fine choices including BlueJ and jEdit.
Certainly JEdit can be configured with the Console Plug-In, and you can read my instructions about that here. But there is a limitation with JEdit's Console. We use the Scanner class sometimes to get input from the System output stream, and Console does not let us get that (You have to run the class file from a true Terminal (or Shell, or Command Prompt) window to do that. That is the advantage of BlueJ.
I like to show the Marine Biology Case
Study with BlueJ, which does have universal cross-platform support, so why not
so since you were going to be using BlueJ anyway,
why not use it with the Exposure Java Chapter Programs? Here's how:
- Install the Java SDK if you haven't already (already included in OSX).
- Install BlueJ, if you haven't done so already (Instructions are
here).
- Download and unzip the ChapterProgs folder, and place the ChapterProgs folder wherever you like (I chose to put it on my Desktop),
If you want, you can just download my BlueJ Projects ChapterProgsBJ.zip and skip to step 9
- Under the FILE menu, select NEW PROJECT. In the picture below you can see I'm calling it "Chap3" and putting it on the Desktop (BTW, BlueJ is written in Java, so the dialog box shows things "unix" style, so the Desktop directory is "/Users/<Your user name here>/Desktop" )

- You should see some like this:

- Under the PROJECT menu, select IMPORT..

- In the IMPORT dialog box you can navigate up a folder with the pop-up menu

- ..or else double-click a sub-folder. Just click ONCE on the Progs03 (..or Progs04...etc) folder, and press the IMPORT Button. If the IMPORT button is dim, you must have double-clicked and gone inside the Progs03 folder...you can't import a file, just a folder...so if you accidently went inside the folder just go up a level with the pop-up menu to select the Progs03 folder

- You should see something like the picture below. Notice that the blue diagonal lines indicate that the java file has not yet been compiled. DO NOT PRESS THE COMPILE BUTTON because this will compile all of them at once. The point of some of these programs is to see the compile errors individually, and see what caused the problem. At this point, you can re-arrange the boxes any way you like. Later, when we have a program with multiple classes, this will be a good way to see organize and design a good OOP project. In the next step I'll show you how to compile them one and a time.

- Move your mouse over one of the files like Java0301 and Right-click (or if you have a one-button mouse, Control-Click), and you should get the pop-up menu that offers you the choice of Seeing the file (Open Editor) or to Compile the file. Go ahead and select OPEN EDITOR. (Double-click also works, but I wanted you to see the pop-up menu with the other choices!)

- You should now be staring at the source code:

- Go back to the project window and right-click Java0301 and select COMPILE (Yes, the Compile button in the Edit window works just as well!)

- Now it made a file called Java0301.class which is the pretty bytecode version of your source code that your Java virtual machine can interpret. So see what it does, Right-click Java0301 again and you see there are some new choices. We can make a new instance of this class with "new Java0301()"--which is NOT what we want at this point--OR, we can call our one and only method called main by selecting void main (String[])

- This particular main method (like most we'll see) does not need or desire any String arguments, so just press the OK button.

- BlueJ will now show you a Terminal window, and you can see that the program printed some numbers, each on their own line:

- Now BlueJ, like many other IDE's like JBuilder or Eclipse, for example, like to think in terms of Projects. Now that we made this Chap3 Project to hold all these example program files, you don't have to import them any more.
You can Revisit them by opening your Chap3 Project from the PROJECT menu's OPEN PROJECT item.

You can also add a single file from any other Progs folder (or one you made in any text editor) here by going the EDIT menu and selecting Add Class from File. You can then edit it, compile it and/or call it's main method to run it. Remember, the name of the file must match the name of the class... if you have a class called Spongebob, the text file has to be called Spongebob.java
- You can then right-click on any file in your open project and select "Open Editor" to see the source. You don't have to go to the Project window to right-click and compile--- look at the top left corner of the Editor window and look for the Compile button! Handy, huh?
Just to see what a compile error looks like in the BlueJ IDE, lets remove one of the semi-colons at the end of the int a; line of the Java0301 program. In the project window Right-click the Java0301 box and select OPEN EDITOR

and remove the semi-colon on line 10:

- Press the COMPILE button, and listen for the sound of a program that won't compile!

- At the bottom of the screen it says ";" expected, and it selected the line immediately after the problem.
- Want to make your own program? While our Chap3 project is open, we'll make a new program by going to the Project window and pressing the NEW CLASS... button.

- Go ahead and select Class and give it a name like "Test"

. When you open it up in the Editor, it will have a bunch of comments and codes that you will have to change to make it look line the code in the book (try changing it to look like the code in Figure 2.36 of Chapter 2 in your text (page 2.46).
Starting from here:

You make it look like:

Run it and...

Just for fun, switch from the "Implementation" View of the code to the "Interface" mode: