CPSC 124 | Introduction to Programming | Spring 2005 |
Jeliot ("The Algorithm Theatre") is a program (actually written in Java) which animates the execution of many Java programs, without having to write the program in any special way. (Mostly; see the limitations below.) Jeliot illustrates each of the steps that the computer goes through to carry out your program, and can be very valuable for learning the semantics (or meaning) of each Java statement.
Jeliot unfortunately has some limitations, so it can't animate any Java program. Here are some of the limitations, and how to work around them. (Don't worry if you don't know what all these things mean - some of them will be covered later in the course.)
Note: if you make changes to a program to support Jeliot, make sure that you either don't save the modified program, or you save it with a different filename - don't overwrite your original program! The safest thing to do is to copy the file (using cp) before opening it with Jeliot.
All classes must be in a single source file. You'll have to paste all non-standard Java classes used in your program into the same file as the main program.
Static variables and constants aren't supported. What this means is that if you use a constant defined in your own program or elsewhere (like Math.PI), Jeliot can't handle it. The fix: In your own code, remove the word "static". If it is defined in other code (like Math.PI), replace it with the actual value (like 3.14159).
As a consequence of the first two points, programs which use TextIO for input (or output) won't work - even if you paste the contents of the TextIO.java into the file with your main program. The fix: replace TextIO.put* with System.out.print, System.out.println, or Output.println() and either replace TextIO.get* with Input.readInt(), Input.readDouble(), Input.readChar(), or Input.readString() or replace TextIO.get* with literals (e.g. replace TextIO.getInt() with 42 or some other integer). Input and Output are classes specific to Jeliot - when the program gets to Input.read*, it will provide you with a way to enter a value. If you replace TextIO.get* with a literal, your program won't pause for user input any more (and will use only those values).
There may be other things that Jeliot doesn't support, but it can handle many things that appear in typical programs.
Start Jeliot by running
/classes/s05/cs124/jeliot/jeliot &
from the command line.
Make sure that the "show history view" checkbox on the Options menu is unchecked. (If you don't do this, the program animation will be slooooooooow.) You should only have to do this once; Jeliot remembers its settings.
Jeliot has two modes: edit and animate. When first started, Jeliot is in edit mode. You may type in a program in the area on the left side of the window (a basic program skeleton is displayed when Jeliot starts up), or you can use the File menu or buttons in the top left of the window to load an existing file.
Next, make any required changes to your program, as outlined under "Limitations" above. If you want to save the Jeliot-compatible program, make sure you choose "Save As" from the File menu and not Save (don't use the "Save" tollbar button either) so that you don't overwrite your original program. You may also use emacs to create a Jeliot-compatible version of your program and load that into Jeliot.
To run your program, press the "Compile" button at the bottom left of the window. The curtains on the right side of the window will be drawn back, and the display will be set up to start animating. You are now in "animate" mode. Use the controls in the bottom left of the window to control the animation - "Step" goes one step at a time, "Play" runs until you hit "Pause", "Rewind" sets the program up to run again from the beginning. You can control the speed of the animation with the slider.
When you are finished animating, click the "Edit" button at the bottom left of the window. This takes you back to "edit" mode and lets you edit the program, load a new program, or exit Jeliot.
I recommend using Jeliot to step through the example programs from class, as well as programs you write. As you step through, quiz yourself on what you'd expect to happen next - and then check your answer by stepping Jeliot. Being able to read a program - that is, to know what the computer will do when it executes a statement - is an important skill for debugging programs as well as for writing programs.