Object Oriented Programming with Greenfoot

Java is an Object Oriented programming language.  ”Hold on, what’s Object Oriented?” will be the first response from most people who are not familiar with programming.  Object-Oriented means that the programming language is based on “objects”, blocks of code that can be reused after they are written.  Greenfoot is an IDE, or interactive development environment, for the Java programming language.

Here’s a sample scenario for you:  we have a World of cells which can hold objects, such as rocks.  So if you want to insert a rock into the world, you can name one object as a rock class, and then reuse it as much as you want.  Here’s how a rock class would look like in Java:

public class Rock extends Actor {

//blankness

}

However, most of us cannot understand this logic behind this basic piece of code.  For those people, here’s an easy approach to programming: Greenfoot, an Java IDE that makes learning programming much easier.

Download and install Greenfoot onto your computer, (a recent Java JDK is required), to experiment with objects, or follow along in this tutorial.

When you open Greenfoot for the very first time, select the “New Scenario”, and find the “Wombats” scenario.  Something similar to the below will open.  In the center is a grid, which is essentially the world in which your objects will live in.  On the right is all classes of objects that are currently written.  These have been pre-made for you.

Greenfoot's Interface

Now, to begin your path into exploring Object Oriented Programming, right click on a “Wombat” on the right panel.  On the right click menu will be a list of “methods”, or functions that your Wombat can execute.  Click “new Wombat()” to initiate a new Wombat, and click inside the World to add the Wombat.  Right click the Rock class, and repeat, this time clicking “new Rock()”.  Place some leaves and more rocks inside your world.

Excellent.  You have just drawn a still-life picture of Wombats and leaves and rocks.  Well, what’s next?  Look on the bottom panel of the Greenfoot window.  There are “Act”, “Run”, and “Reset” buttons.  Press run to make the Simulation run, and watch the wombat move around.  In this sample scenario, the Wombat has been coded to not run into rocks, and eat the leaves.  Your scenario should look something like this at this point:

The Scenario in Action

Well now you may be wondering how this scenario works on the inside, and how the coding looks like.  Right click on the “Wombat” class on the right panel, and select “Open Editor”.  Behold, a multitude of code!  If you already know how to program, you can attempt to modify the code, and tell the Wombat to do other random tasks.  If you don’t, you may want to check out the Java site for tutorials and such.  Click here to check out the online Greenfoot Gallery for scenarios other people have created and published.

Now, for Greenfoot’s rating.  Note that this is for people who have a slight idea of programming.

Performance: 4.5
Features: 4.1
Ease of Use: 4.9
Value for Money: 5
Appearance: 4.7
Overall Rating: 4.595

The bottom line is that Greenfoot is a good IDE for students, such as those taking Computer Science courses.  Greenfoot doesn’t pack as many features as professional IDE’s such as Netbeans, but has the perfect amount and a very good usability for those beginning programming.

So, tried out Greenfoot and liked it?  Or do you want to request tips on how to program?  Leave your comments below.

By
Spaceblue is TechAirlines' chief graphics designer and co-founder. In his free time, he likes to program in Java, admire architecture, and tackle NP-complete problems.