up previous next contents index
Next: Compiling the HelloWorld program Up: Getting started with Lego Previous: no response from crx   Contents   Index

Writing your first Lejos program - "Hello, world"

The next thing we'll do is to create and run a simple program on the RCX. Traditionally a "Hello, world" program is used to introduce new developers to a language, and in this case I'll use a similar program to introduce you to this new Mindstorms environment. I've found it very helpful to start with a small program like this, before you go on to tackle the big fish.

Here's the Java source code for a simple HelloWorld program, specifically HelloWorld.java:


import josx.platform.rcx.*;

public class HelloWorld
{
  public static void main(String[] args)
  {
    LCD.print("Hello");
  }
}

Notice with this program that I only printed "Hello", and not "Hello, world" like I'm supposed to. Why is that?

Well, when you look at the yellow RCX, or "brick" as it is called, you'll see that the LCD screen display only permits seven characters. Therefore, I could not get the entire "Hello, world" phrase out there, and I just stuck with "Hello". As you'll learn in your Mindstorms programming, everything in this environment is smaller than you might otherwise be used to, including available RAM and the LCD.



Subsections
up previous next contents index
Next: Compiling the HelloWorld program Up: Getting started with Lego Previous: no response from crx   Contents   Index