Introducing Greenfoot (Java)

I’ve looked at drag and drop code options, and I’ve looked at proper typed code options; this time I’m going to look at something that bridges the gap between the two.

Greenfoot is produced by the University of Kent, and provides a gentle introduction to Java via a system focused towards graphics – a grown up version of Scratch, almost, with its sprites.  The user is writing real Java, but in a very structured environment.

Java is an Object-Oriented language: this means that you create classes (categories) of objects, which can do certain things, and you can create sub-classes of those classes, which either extend or change the abilities of the parent class.  For example, when I first learned OOP (object-oriented programming) we learnt using frogs, little creatures who could move and jump.  We developed those into hoverfrogs (who could also hover in the air) and scared hover frogs (who could hover but only to a certain height).   So subclasses are developed from their superclasses and can do everything they can do (they inherit the ability to do these things) and can do their own special things as well.  This means that you can reuse code, instead of writing everything from scratch.

Greenfoot main screen

Greenfoot main screen

The Greenfoot site has a few tutorials to get you started with the basics, but to really get to grips with it I recommend Michael Kölling’s blog, which contains a series of videos that take you through step by step.

The Greenfoot screen has two areas: there is the world itself, and the list of classes that make up the world.  Two essential classes exist – World and Actor classes.  World classes contain the sorts of methods that a world in general needs to respond to; the world you wish to use in your program is created as a subclass of World, and has its own settings, including size and graphic.  The other important class is the Actor class.  This has its own methods, and any object you wish to place in the world inherits those methods as well as having its own.

simple greenfoot code

Simple Greenfoot code

Here we have the World, from which we have TurtleWorld, the world that we are running at the moment.  For the Actor, we have the original Actor class, then an  Animal class, then a Turtle class.  The Animal can do everything an Actor can, plus a few extra things such as tell whether it’s at the edge of the world, and the Turtle can do anything else that we design it to.

The code editor is reached by right-clicking on a class, and I found the colour coding in this editor incredibly useful: it really makes nested statements clear, and there is a code helper as well, accessed by starting to type a method then using CTRL[space] to see possibilities.

The first few lessons get as far as making the turtle move randomly onscreen and turn when it reaches an edge.  This leads on to making a simple game.

greenfoot class methods

Inherited methods can be easily found

Greenfoot is a gentle way to introduce a beginner to the idea of classes and inheritance, and writing methods for classes.  The actor class contains the method act(), which is an empty method.  This method must be defined in each class you wish to use in your world, and pressing the Run button on the scenario calls the act() method repeatedly on every single object in the world.  This leads neatly to the prospect of creating different objects, telling them how to act and putting them into the world together to see what happens.  So far in my world I have turtles who move and turn and eat any lettuces they come across and lettuces which just sit waiting to be eaten.

greenfoot code completer

Greenfoot code completer

The teaching materials for Greenfoot seem very good quality, and the projects on the website indicate that it has many possibilities and is an excellent way to introduce object-oriented programming, but after an initial session with it I still feel I need to learn a lot more before doing what I want to do with it rather than just playing with the techniques I’ve learned, and I’m not sure yet how it would fit in with the GCSE computing curriculum.

It does, of course, have the advantage that it uses a proper professional programming language that is also easily portable between platforms (you’re not tied to Windows, unlike Small Basic), and it has lots of really useful features that make it easy to understand and start using for those new to programming.

More to come, then, on Greenfoot!

 

Advertisements

About emmyleigh
Writer/editor/proofreader who loves technology

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: