LJV Tutorial

The purpose of this tutorial is to get you up and running quickly*.

GraphViz must be installed and LJV must be available to the project before proceding.

*LJV contains many options not illustrated in this tutorial. For more information follow the examples link or read the abstract at http://www.cs.auckland.ac.nz/~j-hamer/LJV.html


The Basics

Consider the following code:

int[] numbers = new int[4];
numbers[0] = 3;
numbers[3] = 11;
numbers[2] = -4;
numbers[1] = 0;

LJV.drawGraph( numbers );

String[] animals = new String[5];
animals[0] = "bird";
animals[3] = "horse";
animals[4] = animals[3].substring(1,3);

LJV.drawGraph( animals );

The first call to LJV.drawGraph saves a file called graph-0.png. When graph-0.png is displayed*, it shows an array of ints (primitives) like the following image:


The second call saves a file called graph-1.png, an array of String objects.


Now, it makes sense why horse points to horse, but the offset and count fields help explain why or also points to horse.



Beyond the Basics

It is possible to have LJV simplify the image, but care must be used not to cause confusion. There are two main things that we can do to simplify the image: choosing to not display certain fields or treating an object as a primitive (like an int, double, or boolean.)

In the following example we will hide the offset, count, and hash fields.

animals[0] = "bird";
animals[3] = "horse";
animals[4] = animals[3].substring(1,3);

LJV.Context ctxt = LJV.newContext();
ctxt.ignoreField("offset");
ctxt.ignoreField("hash");
ctxt.ignoreField("count");
LJV.drawGraph( ctxt, animals );


In this image it is not so clear why or points to horse.


Now we will treat Strings as primitives. This can greatly simplify complex images by using the objects toString() method in place of a reference to the object. However, it may be a good idea for students to have a good grasp of the difference between primitives and objects before using this. Another minor issue. Is it a null reference or a String that contains “null”?



Click on the image to view the source code.

Ideas


* Paint, Windows Picture and Fax Viewer, etc. can be used to display the images.