Java Magazine Logo
Originally published in the May/June 2014 issue of Java Magazine. Subscribe today.

Part 1: Interactive Objects with BlueJ

by Michael Kölling

Published May 2014

Interactivity and visualization help beginners learn and form mental models.

When you talk with people about learning to program, and especially learning to program in Java, the BlueJ environment is often mentioned as a good introductory environment to get started. And with good reason: BlueJ is an excellent environment in which to gain a good understanding of fundamental principles of object-oriented programming. When asked why beginners should not just start by using Eclipse or NetBeans— environments known for their excellent toolset and great functionality—the answer typically points to the great value of BlueJ’s simplicity and interactivity for gaining a thorough understanding of programming principles.

But what does this really mean?

When talking about BlueJ, it is not immediately clear what we mean by interactivity, nor is it clear why that matters. In this two-part series of articles, we will explore and discuss BlueJ’s interactive features in detail to see what they can do for you and why you should care.

It’s Not About Syntax

Learning to program is not about syntax. Well, at least not mainly about syntax. Learners new to programming often struggle to get their semicolons in the right places, match their curly brackets, or remember the syntax of a for loop. They often think that this is what programming is about: learning to get the syntax right. But of course it isn’t.

Beyond Syntax

Learning to program is not about syntax. Well, at least not mainly about syntax. All of us who have been around programming for a while know that syntax is neither the interesting nor the hard part.
All of us who have been around programming for a while know that syntax is neither the interesting nor the hard part. In fact, every student at the university where I teach will eventually learn the syntax of their first programming language. It seems hard to some of them at first, but it’s actually the easy part.

No; programming—in this case, object-oriented programming—is about learning how to translate your problem into a program structure, how to design your object interactions, and how to structure your classes. It is about designing algorithms and interacting object structures. And this is hard.

To do this effectively, it is crucial to have a well-developed mental model of object interactions—both how they work in general and how they are arranged in the particular program you are working on.

And this is the crucial difference between beginners and experts: experts have a well-developed mental model of the fundamental principles of object orientation, while beginners do not. Beginners need to develop this mental model, and an educational programming environment must help learners do so.

Environments for Experts, Environments for Learners

Environments designed for professionals—NetBeans, Eclipse, and the like—work very well for experts. They provide a great toolset for programmers who know what they are doing, but they do little to help learners develop the mental models they need to become good programmers.

The main focus in these environments is on source code. Beginners using these systems stare at lines of code, so it is not surprising that what they think about is lines of code. Yet, what is really much harder, and much more important, to learn are the fundamental abstractions: classes, objects, and interactions. These are not well represented in professional environments. Objects, for example, hardly exist as a tangible abstraction in a typical interface. Students look at lines of Java code and struggle to understand the difference between classes and objects.

Starter Kit

BlueJ is designed to offer just the right toolset for beginning programmers. It appears simple, yet does sophisticated things to help them work and learn.
This is not a problem for practiced programmers, because they have a working model in their minds. However, for beginners this is a fundamental problem—a much harder and more fundamental one than the question of where the semicolons go—and they get no help from the environment.

An educational development environment must help learners develop the mental models needed, and it must put the important abstractions—classes, objects, and method calls—in front of the students’ eyes and let them think and talk about them.

And this is exactly what BlueJ does. That is why starting with BlueJ will give beginners a stronger foundation in programming principles. Once they have developed a good working model of object-oriented program execution, they are ready to leave BlueJ behind and switch to a professional environment. But a programmer without a strong foundation in the fundamental principles is a dangerous thing.

A Few Words About Simplicity

At the beginning, we mentioned simplicity and interactivity as the two important points. Simplicity is the easier one to discuss; it is easy to see, and most people get the point quickly.

Professional environments offer many tools that are helpful, and often essential, for experts, but these can easily become a hindrance, rather than help, for learners. Beginners use only a small fraction of these tools, but they initially don’t know which fraction they need to use. Finding the right workflow is made harder by the presence of unwanted options, and orienting yourself in the environment is distinctly difficult on your first encounter.

Get Visual

BlueJ has various bits of functionality not found in many other environments; most important among them is a greater level of interactivity and visualization. These are the important tools for learning to program and forming your mental models.
Choice, for people who don’t need it, is a bane, not a favor.

BlueJ is designed to offer just the right toolset for beginning programmers. It appears simple, yet does sophisticated things to help them work and learn. After only a short time, users feel comfortable in the environment and feel they know it well, and BlueJ blends into the background. Learners don’t need to think about the environment; they think about programming principles. The development environment becomes a silent helper, not a problem to be mastered in itself.

newtojava-f1

Figure 1

BlueJ’s interface (see Figure 1) appears very simple and unthreatening. This should not be mistaken as simplicity of functionality: BlueJ offers some sophisticated tools that help learners along the way, and we will discuss some of them shortly. In fact, one of the greatest achievements of BlueJ is to present a complex problem domain—programming—in a simple fashion. One of the leading design goals of BlueJ is well expressed in a famous quote by Antoine de Saint Exupéry:

“Perfection is achieved,
not when there is nothing more to add,
but when there is nothing left to take away.”

But it is also important to note that this does not mean that an educational environment is simply a cut-down version of a professional one. BlueJ’s toolset is not a subset of one of the bigger systems. It is not merely about offering fewer tools, but about offering different ones.

BlueJ has various bits of functionality not found in many other environments, and most important among them is a greater level of interactivity and visualization. These are the important tools for learning to program and forming your mental models, and, therefore, they will be the focus of the rest of this article.

The Killer Features: Interaction and Visualization

A previous issue of Java Magazine introduced BlueJ’s features by presenting a small programming example, and another issue discussed testing in BlueJ in more detail.

Both of these articles touched on BlueJ’s interactive features and made use of some of them. However, they presented only a partial insight into BlueJ’s toolset. We will now discuss BlueJ’s interaction features in more depth—the first few here, and the rest in Part 2.

Classes and Objects

The first, most obvious—and most fundamental—aspect of BlueJ’s functionality that is relevant here is its presentation of classes and objects.

When opening BlueJ, the first thing shown to a user is a diagram of the classes in the project and their relationships. The diagram’s arrows display inheritance and uses relationships—which is when a class references another.

The Basics

BlueJ is an excellent environment in which to gain a good understanding of fundamental principles of object-oriented programming.
A user can then interactively create objects by right-clicking any of the classes and invoking a constructor from the class’ menu (see Figure 2). Every constructor of the class is shown in this menu and can be interactively invoked. Objects, once created, are shown in red on the object bench along the bottom of the main window (see Figure 1).

newtojava-f2

Figure 2

Once an object has been created, a menu offers all the object’s public methods, and any of them can be interactively invoked by selecting it from this menu (see Figure 3). If the method has parameters, they can be entered; otherwise, the method executes immediately.

newtojava-f3

Figure 3

Why Is This Important?

Even the first few simple visualizations and interactions shown so far have a fundamental effect on the understanding of the principles of object orientation.

First, the division of a program into classes is illustrated. The diagram conveys the message that an object-oriented program is represented by a set of cooperating classes, and that these parts of a program can be examined and understood separately. Presenting the classes in a diagram illustrates their relationship better than the simple list used in many other environments.

Second, the difference between classes and objects is implicitly apparent. Understanding this difference is one of the great problems for beginning students. Most teachers have struggled with this. In traditional environments, students start by looking at source code. What do they see—a class or an object? Well, the answer is neither or both. Which one it is depends on context: whether the student thinks about the static or dynamic properties of their program. Understanding the difference is difficult.

In BlueJ, the distinction is immediately clear: from a class, we can create objects. In fact, we can create as many objects as we like. In BlueJ, the question never comes up. Students get a feeling for classes and objects almost automatically, with little effort. Both the visualization and the interaction (the act of creating the object) support this understanding.

Third, it becomes immediately clear that we can communicate with objects by invoking their methods. Students can experiment with objects, try out what they do, gain experience with parameters and return values, and investigate a project or parts of a project. The understanding developed through these activities will be very useful once students start writing code.

Understanding object orientation is about understanding three big concepts that define objects: state, behavior, and identity. Even these first simple interactions already illustrate two of them: behavior and identity. (We will soon see how state is visualized.)

No Test Drivers

Learn More


 Download BlueJ for free

 Example projects at the BlueJ book website

One of the important aspects to emphasize about BlueJ is ease of interaction: methods can be executed individually without the need to write any test drivers. No public static void main is necessary. This means that classes and objects (and also students) can become active before writing code. Easier and quicker interaction means more interaction. More interaction means better understanding.

The possibility of interaction fundamentally changes how a learner can approach gaining an understanding of programming principles.

Conclusion

The use of visualization and interaction leads to the formation of better and stronger mental models that then form the basis for reasoning about programs and programming. So far, we have seen only a small example of BlueJ’s visualization and interactive features. In the next article, we will discuss many more tools that support this process.


kolling-headshot



Michael Kölling
is a professor at the School of Computing, University of Kent, in Canterbury, England. His research interests are in the areas of object-oriented systems, software tools, programming languages, computing education, and HCI. He is the author of two Java textbooks and is the lead developer of BlueJ and Greenfoot.