Installing and Using BlueJ

Margaret Lamb
School of Computing
Queen's University
Kingston, Ontario

The procedure for installing BlueJ is pretty simple. It used to be that to use BlueJ with Windows you had to install a JDK first. This is no longer the case; BlueJ comes bundled with a JDK. So all you have to do is to go to the  BlueJ web page and click "BlueJ Installer With Java 8 JDK", which will download and install a JDK as well as BlueJ. If you already have a fairly up-to-date JDK and don't want to waste time and space by installing another one, click "BlueJ Installer" instead. At some point in the installation for the latter you will be asked to provide the location of the JDK on your computer.

BlueJ supplies a nice tutorial that you should read if you have trouble using the tool. To see it, start up BlueJ and choose "BlueJ Tutorial" from the help menu.

This rest of this page contains my instructions for getting started with BlueJ as quickly as possible. It will walk you through writing and running a simple Java program with BlueJ.  Before you start, you need to understand how BlueJ views projects.  With BlueJ, you can't edit, compile or run a file unless it's part of a project.  If a program consists of several Java files, they must be grouped together in the same project.  Even if your program contains only one file, you must put it in a project. BlueJ creates a folder for each project.  The following are step-by-step instructions for creating and running a simple Java program using BlueJ:

  1. Start BlueJ.
  2. Create a new project: from the Project menu, by choosing New Project.  You'll get a file open dialog in which you should create a new folder to hold your project. For example, suppose you have a folder called c:/CISC121 and you would like your new project folder to be a sub-folder of this folder, called assignment1. Navigate to c:/CISC121 and type the name assignment1. BlueJ will create the new folder c:/CISC121/assignment1 and open it as a new project folder. BlueJ will create two files inside this new folder. One is called README.TXT, which you may use to record information about your program if you wish. The other is called package.bluej, which is for BlueJ's use only and you should leave it alone.
  3. Now you have a new, empty project. When you have a project open, the main BlueJ window always shows you the files in your project.  Right now, there will be only one file showing.  If you double-click on it, you will see that it is the README.TXT file. Record any information you like, then use the Close button to get rid of that window.
  4. To create a new Java file for your program, click the New Class button.  You'll be asked for a name; this will be the name of your Java class.  For example, if you want to create a class called Class1, type "Class1" (not Class1.java). BlueJ will create a file called Class1.java.  Under "class type", leave "class" selected.  Now you'll see another file in the main BlueJ window.  It will have diagonal lines across it, showing that the file has not been compiled.
  5. To edit your Java file, double-click its box in the main BlueJ window.  This will create an editor window for your file and you'll see a little template BlueJ created.  You can edit it to create your own class, or just type control-A and then Delete and start from scratch. When you have finished, type control-S to save the file.  Notice that the main BlueJ window is still there behind this editor window.  
  6. If you'd rather use an existing Java file, go to the Edit menu and choose Add Class From File.  Browse to the file.   BlueJ will make a copy of this file and put it into your project folder. You can then edit it as described above.
  7. If your program will contain several classes, use the procedures above to create or copy each class. 
  8. There are two ways to compile classes.  To compile a single class from its editor window, push the Compile button or type control-K.  You'll get a message on the bottom of your screen indicating whether the compilation was successful.  If you have several files in your project that need to be compiled, it's quicker to compile from the main BlueJ window. The "Compile" button in the main BlueJ window (or "compile" under the "Tools" menu) compiles all of the classes that haven't already been compiled. If you want to force a recompilation of every class in your project, choose "Rebuild Package" from the "Tools" menu.
  9. To run your program, go to the main BlueJ window.  You may be looking for a "run" button, but there isn't one.  Instead, right-click on the icon for your main Java file.  There will be an entry for every constructor and static method in the class.  This can be very useful for testing, but for now just pick the main method.  A method-call window will pop up; click OK.  This will run your main method.  A terminal window will pop up and show you the output from your program.
  10. Run your program a second time.  You'll see that the output from that run will be appended to the output from the first.  
More about the terminal window:
  1. You can view or hide the terminal window at any time: in the main BlueJ window, check or un-check View | Show Terminal.
  2. Even if you hide or close the terminal window, the output from all your runs will remain in the window.  If you don't like this effect, you can clear all output from the window at any time: from the terminal window, choose Options | Clear.
  3. If you want to save the output of a program, clear the window and choose Options | Unlimited Buffering.  Then run your program, and choose Options | Save To File, and your ouput will be copied into a text file.  (If you want a .txt extension, remember to specify it when you give the file name.)  Alternately, you can use the normal Windows keyboard commands (control-C and control-V)  to copy output from the window and paste it into another document.
  4. If you don't like seeing the output from all of your runs, go to the Options menu in the terminal window and choose "clear screen at method call".

You may have a Java program that you've written using another tool that you would now like to work with BlueJ. In that case, from the Project menu choose "Open Non-BlueJ..." and select the folder containing your program. BlueJ will add the necessary extra files to that folder so that you can run the program as a BlueJ project.

That's enough to get you started writing and running programs. BlueJ has many other features, which you may want to explore once you're familiar with the basics of BlueJ. Besides the BlueJ Tutorial mentioned above, the BlueJ web page lists several helpful documents, FAQs and mailing lists.