Comments:

This simple example illustrates the very basic structure of a reactive program using SugarCubes:


How to compile?

(Instructions provided for a UNIX system using JDK 1.1.x or higher version number).

javac -classpath SugarCubesv3.0.3.jar HelloWorld.java


How to execute?

java -cp SugarCubesv3.0.3.jar:. HelloWorld

You should get the following result:

        instant 1: 
        Hello World!
        instant 2: 
        instant 3: 
        instant 4: 
        instant 5: 
        instant 6: 
        instant 7: 
        instant 8: 
        instant 9: 
        instant 10: 

import inria.meije.rc.sugarcubes.Machine;
import inria.meije.rc.sugarcubes.SC;
import inria.meije.rc.sugarcubes.Program;

class HelloWorld
{
    public static void main(String[] args){
        // First one writes a reactive program.
        Program print = SC.print("Hello World!\n");

        // Then one makes a reactive execution machine.
        Machine machine = SC.machine();

        // One adds the program into the machine.
        machine.addProgram(print);

        // One makes the machine reacts for ten consecutive instants.
        for(int i = 1; i<=10; i++){
                System.out.println("instant "+i+": ");
                machine.react();
        }

    }
}