Java Programming using BlueJ on ESU Systems

 

BlueJ is an Integrated Development Environment (IDE) designed for introductory programming courses in Java.  This IDE is not a full-featured, industrial strength IDE such as Eclipse (a free and excellent IDE).  On the other hand, it does not have the learning curve that a commercial level IDE has. 

 

One excellent feature that BlueJ contains is the ability to write a class without a main program, and then create instances of the class to test it without having to write a main (driver) program.  It also contains a debugger, a tool that all good programmers rely on heavily.

 

Note Well: On the ESU network, the user’s “My Documents” folder does not live on the C: drive as it does on a personal computer.  It is “mapped” to a file server named shemp.  Every student in the university has a private folder on shemp that is accessible from any networked computer.  However, this mapping uses Uniform Naming Convention to do the mapping (UNC).  For some reason, BlueJ will freeze if the user creates a project in the My Documents folder.  Instead, the user must always create projects on the “U:\” drive --- which is shemp --- which is the same as My Documents.  For some reason, using the alias My Documents rather than directly using the drive letter “U:\” causes a deadlock to occur even though both names map to the same location.

 

To create a BlueJ project, run BlueJ.  You will see an initial screen as below:

 

 

Select Project, then New Project. This next step is critical.   In the dialog box that indicates “Look In”, select your login name on file server shemp (U:\), not my documents.  Shown on next page

 

 

When a project is created (for example, myProject), a folder is created within which several files are created.  You may then create new classes in the project.  For example, if you want to create a class to display Hello World, you could select Edit … New Class, and give it a name such as HelloWorld (no spaces).  You will see a class appear in your project window as shown below:

 

The hash marks through the class indicate the class has not been compiled yet (translated into something that can be executed).  Double-clicking the class will bring up an editor. You can the modify the class.  On the next page, see the original class:

 

 

The user can change this.  For example, you can replace all this text with the following:

 

/**

 * My first program

 */

public class HelloWorld

{

   public static void main(String[] args)

   {

       System.out.println("Hello World");

   }

}

 

Then click the Compile button.  If you made no mistakes, it will say “done”, otherwise it will highlight the line that has an error. 

 

Your class will now no longer have hash marks.  You may “run” the program by right-clicking the class and selecting main( ).  You will see a dialog box.  Simply click OK.  You will see a terminal window appear with “Hello World” displayed.  This is the simplest program you can write and often the first program a programmer will write when trying out a new language. 

 

One nice feature of BlueJ is that you can create a class that does not have a main program but still test your class.  For a very simply example, we may have a class that creates either a greeting or a goodbye.  Create a new class named Greeting and enter the text as follows:

 


public class Greeting

{

      // instance variables - replace the example below with your own

      private String name;

 

      /**

       * Constructor for objects of class Greeting

       */

      public Greeting(String theName)

      {

          name = theName;

      }

 

      public void Hello()

      {

          System.out.println("Hello " + name + ". Nice to see you.");

      }

     

      public void GoodBye()

      {

          System.out.println("Sorry to see you go " + name);

      }

}

 

Click the compile button and fix the errors.  You should see the following:

 

 

Now --- right click the Greeting class. You will see a dialog box appear.  Enter your name with quotes as in “Chas Cole”.  Make sure to use the double quotes.  Do it again but with another name.  You will see two instances of the Greeting class (called Objects) on the “Object Bench”.  If you right-click either of these, you may select a hello or goodbye method to test it.  You will notice that each object will produce a message with its own private name.