BlueJ and Greenfoot: The best IDEs to learn Java
You say you want to learn Java. It can be a daunting language. It might even seem impenetrable if you’re a new programmer. But, you take a deep breath and resolve to give it a go. Ok, first things first: You need one of those integrated development environments (IDEs) you’ve read about. A single application in which you can edit, build, run, debug, and deploy your soon-to-be-written Java application.
Several popular, free Java IDEs are available: Eclipse, NetBeans, and the community edition of IntelliJ, for example. You choose one, download and install it, and in a very short time you realize that you now have two things to learn: Java and the IDE. Your chosen development tool is as impenetrable as the language it’s supposed to help you with.
Enter BlueJ and Greenfoot, two IDEs very specifically designed for beginners. They are the product of a team based at King’s College in London (though team members have, at times, been affiliated with universities in Australia and Denmark). The creators of BlueJ and Greenfoot selected the feature set and interface design to not overwhelm beginners.
In fact, as Neil Brown, the lead developer explains, BlueJ’s and Greenfoot’s features are “…revealed as users come to them.” You are not thrown into the deep end of the pool. Consequently, both provide an easy introduction not only to the Java language, but to the tools and techniques needed to build applications in that language.
Learn Java with BlueJ
BlueJ first appeared in 1999, named simply Blue. At that time, it was both a development environment and a language. When Java appeared, the tool was rebuilt using Java as the language and the name was changed to BlueJ.
Editions of BlueJ exist for Linux, MacOS, and Windows. BlueJ also comes in a generic form: packaged as a JAR file so that BlueJ can be installed on any system that supports Java. The current version of BlueJ (4.2.2 at the time of this writing) requires JDK 11 or later, and as such must be run on a 64-bit operating system. Earlier, 32-bit versions exist, but they are no longer being developed.
I first became aware of BlueJ (and Greenfoot) when I found them pre-installed on a Raspberry Pi 4 that I had gotten last year. I later learned that BlueJ had been installed on the Raspberry Pi since 2015.
Open a project in BlueJ and you’re presented with a refreshingly sparse window: menu bar across the top, toolbar to the left of a large workbench area, and a smaller object bench pane below. Buttons on the toolbar let you create a class, define an inheritance relationship, or compile a class. Project classes appear in the workbench as a kind of pared-down UML diagram, and while BlueJ is not a full-blown visual development environment, it’s enough of one so that you can see the relationships among entities in your program, but not lose sight of the code.
Double-click on a class icon in the workbench, and its source opens in the editor, where another visual assist is revealed: scope highlighting. With scope highlighting, nested blocks of code are literally highlighted in different colored backgrounds, so you can quickly see the area covered by a method within a class, a
for loop within a method, an
if statement within that
for loop, and so on. Code structure is made instantly apparent.
Right-click on a class in the workbench, and a new menu appears that—depending on the nature and makeup of the class—lets you compile the class, inspect its contents, create a corresponding test class (more on this later), execute a class method, or instantiate an object of the class. Here, BlueJ’s interactivity takes center stage.
Classes can be individually compiled; you don’t have to rebuild an entire project if you’ve modified a single class. Choose to execute a class method and a dialog pops up, prompting you for the method inputs. Enter the inputs, click OK, and another dialog materializes, showing the return value and its data type.
If you instantiate a class, an icon representing the new object appears in the object bench. As with classes, you can right-click the object icon and examine the object’s contents. You can also execute individual object instance methods; dialogs appear (as above) for entering input arguments and displaying return values.
BlueJ wouldn’t be a complete IDE without a debugger. You can set debugger breakpoints in BlueJ the same way you would in other IDEs. In the editor, just click in the column to the left of the targeted source code line. When, during execution, the breakpoint is triggered, BlueJ’s debugger pop-up opens, showing threads, call stack, lock static, and instance variables, as well as the familiar debugging controls (step, step into, continue, and stop). Once again, BlueJ’s uncluttered presentation doesn’t stand between you and the task at hand.
As mentioned above, BlueJ can create a test class from a class icon’s right-click menu. The auto-created class is a skeletal JUnit test class (JUnit 4 is integrated with BlueJ). It consists of empty constructor,
tearDown() methods. You can either build test methods by opening the class’s source in the editor, or use a sort of built-in wizard that—via a series of dialogs—leads you through creating test methods.
Similarly, BlueJ provides assistance for creating JavaFX and Swing graphical applications. Tutorials are provided, and working through the JavaFX tutorial reveals the real benefit of using BlueJ’s ability to execute methods on “live” objects (while the application is running). You can actually see the result of a method call on a graphical component.
BlueJ’s built-in interactive tutorials get you off the ground. If you need even more educational materials, the book Objects First with Java, co-written by BlueJ creator Michael Kölling, uses BlueJ as the development environment to present a beginner’s approach to object-oriented programming in Java.
Learn Java with Greenfoot
Built on BlueJ by the same creator, Michael Kӧlling, Greenfoot is a more specialized IDE than BlueJ. While BlueJ is often used in the setting of a university-level introductory programming course, Greenfoot is targeted at younger users; as young as 14 years. To capture and hold a younger audience’s attention, Greenfoot has been crafted as a “simple Java IDE and animation framework.” Which means it’s for building games.
To understand Greenfoot, you must first learn its terminology. A Greenfoot project is a “scenario.” Every scenario has a “world,” which is your game’s playing field. It is a two-dimensional container inhabited by “actors.” Be careful here—a Greenfoot actor is not the particular sort of object-oriented, concurrent programming entity of the same name (see https://en.wikipedia.org/wiki/Actor_model). Greenfoot actors are your game’s playing-pieces.
A Greenfoot actor has attributes and methods (characteristics and behaviors). One characteristic of an actor is its appearance—the icon displayed in the world to represent that actor. Greenfoot comes with a variety of actor images to get you started, or you can create and import your own image.
Greenfoot’s visual arrangement is a mirror-image of BlueJ. Greenfoot’s main window is the world. To its right, a vertical toolbar is populated with inheritance diagrams of project classes. Typically, there are two inheritance “trees” in the toolbar, one rooted in the base
World class, the other rooted in the base
Actor class. Derived classes branch off these two roots.
As with BlueJ, double-clicking on a class’s icon opens its associated source in an editor window. The Greenfoot editor is identical to BlueJ’s, which is not surprising, as almost all of BlueJ is executing underneath Greenfoot. So Greenfoot’s editor has BlueJ’s scope highlighting, and Greenfoot’s debugger works exactly like BlueJ’s.
Modify a class in the editor, and its icon in the inheritance diagram is cross-hatched. This indicates that the class must be re-compiled before it can be used to instantiate an object. In addition, all objects in the world derived from that class become blurred (no longer in sharp relief) to show that they are now out-of-date. Fortunately, as in BlueJ, you can compile classes individually.
Once you’ve instantiated an actor, you can place it in the world by dragging and dropping its icon into the world’s window-pane. Strictly speaking you don’t have to put an actor in the world before any of the actor’s methods can be called. Right-click on an actor to select a method to call. If the method requires input parameters, a dialog opens that allows you to supply the parameter.
Time must flow in the Greenfoot world for actors to have movement. But it’s a digital world, so time advances in ticks of an internal clock—an update loop. Two buttons—Act and Run—control the execution of that loop. Click the Act button, and the loop runs once. Click Run, the button becomes Pause, and the loop runs until you click the button again to stop it. These buttons are, of course, supremely useful for testing and debugging your game.
If you must suspend your scenario’s development session and you want to pick up where you left off, you can save the world (which is a lot less dramatic than it sounds). Greenfoot will capture the location and state of actors in the world, and encode that information for a method that’s called by the actors’ constructor. The upshot: Your stage reassembles itself the next time you start up the Greenfoot IDE.
During game play, what happens when two actors collide? Or something blows up? A game must have sound effects. Greenfoot can import .wav files into a scenario, and methods let you play those sounds when specific events are triggered. Nothing stops you from borrowing any of the sounds provided with the various tutorials on the Greenfoot website. But in the event you want to create your own, Greenfoot provides a built-in sound recorder. The recorder’s editing capabilities are simple but usable. It’s basically a “capture and trim” system.
Finally, if you need game ideas beyond those provided in Greenfoot’s tutorials, Greenfoot’s website is teeming with scenarios created and uploaded by users from around the world. Some can even be played online. The quality is understandably spotty, but the variety of games testify to Greenfoot’s versatility.
Stepping stones to pro Java programming
According to creator Michael Kӧlling, while BlueJ is typically used in a university’s introductory programming course, Greenfoot is suitable for use in high school. Nevertheless, regardless of your age, you can get plenty of mileage out of either IDE if you’ve just set foot on the road to Java self-education.
Beyond the already-mentioned tutorials, there is a considerable amount of supporting materials on the BlueJ and Greenfoot websites. We’ve already mentioned the BlueJ textbook; a textbook also exists for Greenfoot, Introduction to Programming with Greenfoot. (See the websites for purchase information.)
Neither IDE is suitable for building product-ready, enterprise-level Java applications. But as introductory vehicles for anyone new to Java, they check all the boxes, and they don’t burden you with toolbar and menu complexity. They are solid, smooth stepping-stones to professional-grade Java development.
Copyright © 2020 IDG Communications, Inc.