Graphing
Calculator
Math
Worksheets
Scientific
Calculator
Chart
Maker


Home
Graphing Calc
Algebra
Fun Games
Geometry
Interactive
Trigonometry
Scientific Calc
Home
Graphing Calc
Algebra
Fun Games
Geometry
Interactive
Trigonometry
Scientific Calc

Create a project and Class with BlueJ

Hello World, BlueJ Style

The only assumptions that this tutorial makes is that a student has some sense of what a class is as well as what System.out.println() method does.


How to Create a Project

  • 1) After opening up BlueJ, select 'new project.' Let's call our first BlueJ project "FirstProject".
  • 2) Your screen should now look like this picture. The blank document with the turned corner represents the project:

How to Create a Class in a Project

  • Not surprisingly, the way that you create a new class is to click on the "new class" button!
  • Let's call our first class "HelloWorld". By convention class names start iwth a capital letter though Java does not require this.
      You cannot have a blank space in the name of a class. ie "HelloWorld" is perfectly ok. "Helloworld" is just as valid of a classname but "Hello World" is NOT a valid clas name.
  • Now let's actually start programming!. To do so, right click on the "HelloWorld" icon and select 'Open Editor'
  • Now, if you've never programmed before, you may see a lot of daunting looking stuff! Eventually though, what you are looking at below will seem quite familiar and not daunting at all. Just ask anyone in the AP class! Here's what my version of BlueJ has as the default code of each class.
  • Now, let's add the code that will print out Hello World when we run the program. Add the following line of code inside the Constructor of HelloWorld.
    System.out.print("Hello World");
    
  • Now that we are done writing our code, let's close the the editor. We must now 'compile' our source code into bytecode. To do so right click on the project and select 'compile'
  • Once the class has been compiled it is no longer striped. We can now run our class.

    Running our first BlueJ Class


  • To run the class, just right click on the HelloWorld icon and select 'new HelloWorld()'
  • There will be a prompt asking you for the instance name. You can use whatever you want here. If you've used Jeroo this is the same as the name of the Jeroo. You can use any valid identifier (an identifier can't have spaces and can't start with a number
    //tom is the instance name of this Jeroo
    Jeroo tom = new Jeroo(1,2);
  • Finally, our first BlueJ class has been compiled and run. You should see the output that is pictured below

Mini Programming Assignment

Step 1) Let's explore how we can create a more flexible constructor. Change the code in your BlueJ class to look like the following. Save and compile the updated class code.

Step 2)Create a new instance of HelloWorld. Notice the difference. This time you are greeted by a prompt. Type in some letters. Make sure that you enclose them with "quotes";

What happened when you input those letters?

Step 3) Try the same thing. Create a new instance of HelloWorld, but this time do not use quotes

As you might be able to tell, our constructor expects quotes around its paramater. This is because our parameter expects a String.


What if we wanted to display TWO different messages?



What if I want my Message to display two different Messages? ie What if I want my object to display two distinct Strings?
Below is a picture of what I want.
There are many ways to solve this problem. Below shows how you can employ code reuse and constructor overloading to come up with a nice solution.
See solution in its own window