Site Overlay

Always trouble with Karel…

Stanford's Karel
Stanford’s Karel

If you want to learn about computer science in general and about Java programming in particular, maybe one of the best learning ressources to look at is the CS106A online course by Stanford University. To get people familiar with programming, the first lessons make use of a virtual robot (“Karel”) created by Stanford to run inside the popular Eclipse IDE. This post shows how to get the Stanford code running in your Ubuntu installation and maybe even under MacOS or Windows.

It’s been a few years though…

Unfortunately, it’s been a while since Stanford updated their course homepage. As ressources date back to 2007, the karel.jar file included in the archive was intended to be compatible with Java 1.6 and Eclipse.

As we are now at Java 1.8, you will get an empty Java Application Screen instead of the Karel Board when you try to launch the Java code of your Assignment.

Trying to run a code with an outdated karel.jar file
Trying to run a code with an outdated karel.jar file

It is often recommended to downgrade your Java to version 1.6. Imho, this is a bad idea: Instead of working with an outdated JRE just to run an outdated jar file, you should rather go to find a current version of a jar file.

So the best way forward is to go for a recent version of with a recent version of karel.jar which runs just fine with Java’s JRE 1.8. Just download it from this page and use it with all Karel-related assignments.

Standard Eclipse or Stanford’s Customized Eclipse?

For Linux users, the choice is easy: As Stanford only supports Windows and MacOS, my advice is to go by the standard Eclipse version. This allows you to have the most recent version of Eclipse and you don’t need the bells & whistles of the customized Stanford version anyway. Just pick the Oomph installer and choose the standard Eclipse Java IDE for Developers. (Not Java EE)

The Run Configuration

To run your code…

  1. Go to Run Configurations,
  2. Click on Java Application (not Applet!)
  3. In the Main tab, Search for the Main class and select stanford.karel.Karel
  4. In the Arguments tab enter code=CollectNewspaperKarel (or whatever the name of the Java app is that you want to run)
  5. Click Run and you should see your Karel application
  6. You may have to load the corresponding Karel world when your application starts.
Karel running in Ubuntu's Eclipse Mars
Karel running in Ubuntu’s Eclipse Mars