TutorialsICSEClass 9Computer Applications

Your First Java Project in BlueJ: Create, Compile and Run a Program

Create your first Java program in BlueJ step by step: make a project, add a class, write and compile the code, run main(), and create an object from the class – the essential first lesson for ICSE Class 9 Computer Applications.

Updated 7 min read
Your First Java Project in BlueJ: Create, Compile and Run a Program

Once BlueJ is installed, the next step is to write, compile and run your first Java program. This lesson walks you through the whole process. It is the same routine you will use for every program in ICSE Computer Applications and ISC Computer Science.

Step 1: Create a new project

  1. Open BlueJ and click Project → New Project.
  2. Choose a folder (for example Documents), type the project name MyFirstProject, and click Create.

A project is simply a folder that holds all your classes.

Step 2: Create a class

  1. Click the New Class button on the left.
  2. Type the class name Hello. Class names start with a capital letter by convention.
  3. Keep the type as Class and click OK.

An orange box labelled Hello appears. The stripes on it mean the class has not been compiled yet.

Step 3: Write the code

Double-click the Hello box to open the editor. Delete the sample code BlueJ inserts and type:

public class Hello {
    public static void main(String args[]) {
        System.out.println("Hello, Java4School!");
        System.out.println("My first Java program in BlueJ.");
    }
}

Step 4: Compile

Click Compile in the editor window, or press Ctrl + K.

  • If the message at the bottom reads "Class compiled – no syntax errors", you are ready to run.
  • If there is an error, BlueJ highlights the line. The most common first-day mistakes are a missing semicolon ;, a missing closing bracket }, and typing system instead of System. Java is case-sensitive.

Step 5: Run the program

  1. Close the editor and right-click the Hello box.
  2. Choose void main(String[] args) and click OK in the dialog that opens.
  3. The Terminal Window opens and shows:
Hello, Java4School!
My first Java program in BlueJ.

Congratulations, you have run your first Java program!

Step 6: Create an object (the BlueJ way)

BlueJ lets you create objects without writing extra code, which is a great way to understand classes and objects. Add a second class:

public class Student {
    String name = "Riya";
    int marks = 95;

    void display() {
        System.out.println(name + " scored " + marks);
    }
}

Compile it, then right-click Student and choose new Student(). A red box appears in the object bench at the bottom. That is your object. Right-click the object and choose display(). The terminal prints Riya scored 95.

Key terms from this lesson

  • Source code: the Java program you type, saved in a file such as Hello.java.
  • Compiling: converting source code into bytecode (Hello.class), which the Java Virtual Machine (JVM) runs.
  • main() method: the starting point of a Java program.
  • Object bench: the area in BlueJ where the objects you create are shown.

What next?

Learn how to take input from the user with the Scanner class and BufferedReader, then practise with our ICSE Class 9 solved programs.