John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 1/21
Visualising Java Data Structures as Graphs
John Hamer
Department of Computer Science University of Auckland J.Hamer@cs.auckland.ac.nz
Visualising Java Data Structures as Graphs John Hamer Department of - - PowerPoint PPT Presentation
Visualising Java Data Structures as Graphs John Hamer Department of Computer Science University of Auckland J.Hamer@cs.auckland.ac.nz John Hamer, January 15, 2004 ACE2004Visualising Java Data Structures as Graphs p. 1/21 The Idea
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 1/21
Department of Computer Science University of Auckland J.Hamer@cs.auckland.ac.nz
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 2/21
■ Student code calls the static method
■ whatever can be any Java object. ■ Dot.drawGraph ◆ traverses the object’s fields using Java reflection ◆ outputs a GraphViz format graph description to a text file ◆ runs the GraphViz processor to produce a PNG (or EPS,
■ Student views the sequence of pictures using a standard
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 3/21
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 4/21
LinkedList size: 0 Entry element: null
header next previous
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 5/21
LinkedList size: 1 Entry element: null
header
Entry element: 100
next previous next previous
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 6/21
LinkedList size: 2 Entry element: null
header
Entry element: 100
next
Entry element: 101
previous previous next next previous
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 7/21
LinkedList size: 3 Entry element: null
header
Entry element: 100
next
Entry element: 102
previous previous
Entry element: 101
next previous next next previous
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 8/21
LinkedList size: 3 Entry element: null
header
Entry element: 100
next
Entry element: 102
previous previous
Entry element: 101
next previous next next previous
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 9/21
■ GraphViz is a widely used, freely available graph drawing
■ Layout is completely automatic and (generally) æsthetically
■ Text input for nodes and edges, with optional attributes
■ Output to a variety of formats (PNG, EPS, SVG, . . . )
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 10/21
■ Brocard —Perl interface to GraphViz for
■ North & Koutsofios —visual debugger, vdbx
■ Thomas Naps’ Visualiser class. Canned
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 11/21
■ Students must be engaged in active learning; ■ tools need to be simple to use; ■ avoid distracting students from substantive course material; ■ for instructors, minimise the effort required to integrate tools
■ software must be reliable.
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 12/21
■ trivial to setup and easy to use (source < 600 lines); ■ active learning —students decide where to place the calls
■ connects code with the Java data model; ■ usable on any Java program; no specific programming
■ allows “wrong” data structures to be viewed (as well as
■ configuration allows broad and precise elision of detail; ■ visualisations can be incorporated in reports, www pages,
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 13/21
■ Strings are objects, but string constants look like primitive
■ Assignment of objects is by reference, primitive types by
■ Object arrays hold references, not values. ■ 2-dimensional arrays are constructed from 1-d arrays (is it
■ Static fields are not part of any object. ■ Inheritance means objects are often not the same as their
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 14/21
HashMap size: 3 threshold: 8 loadFactor: 2.0 modCount: 3
table
Entry key: three value: 3 hash: -741826716 Entry key: two value: 2 hash: -1000502134
2
Entry key: one value: 1 hash: -953555362
next
■ Arrays are displayed with elements
■ Values in primitive arrays are shown
■ Object arrays just contain links. ■ Primitive fields are shown inside the
■ Object fields are shown as labelled
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 15/21
■ Show the full internal state of String. ■ Acknowledge String is an object, but hide the internal
■ Pretend String is a primitive value (not an object).
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 16/21
String
count: 5 hash: 0 String
count: 5 hash: 0
1
H e l l
value
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 17/21
■ Can be used with any object, by calling the
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 18/21
■ Can be used with any object, by calling the
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 19/21
■ GraphViz has limited support for node shapes, label
■ Graphs of, e.g., Java AWT components, can be immense.
■ Work in progress on integration with a debugger (Jacob
■ Also, “draw” command extension to the BeanShell (an
■ More elision controls. ■ Experimental features for dynamically selecting attributes
■ Interactive graphs —select a node and expand or elide.
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 20/21
■ Light-weight, general purpose visualisation tool for Java. ■ Useful in elucidating the Java data model, especially
■ Less suitable for classical array data structures (c.f., Naps),
■ Freely available from
John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 21/21
{0->"0",1->"1",10->"10",11->"11",12->"12",13->"13",14->"14",15->"15",16->"16",17->"17",18->"18",19->"19",2->"2",3->"3",4->"4",5->"5",6->"6",7->"7",8->"8",9->"9",a->"a",b->"b"} Node key: 3 value: "3" level: 4
root
Node key: 11 value: "11" level: 3
left
Node key: 7 value: "7" level: 3
right
Node key: 1 value: "1" level: 2
left
Node key: 15 value: "15" level: 3
right
Node key: 0 value: "0" level: 1
left
Node key: 10 value: "10" level: 1
right
Node key: b value: null level: -1
left right left right right left
Node key: 13 value: "13" level: 2
left
Node key: 17 value: "17" level: 2
right
Node key: 12 value: "12" level: 1
left
Node key: 14 value: "14" level: 1
right left right left right
Node key: 16 value: "16" level: 1
left
Node key: 19 value: "19" level: 2
right left right
Node key: 18 value: "18" level: 1
left
Node key: 2 value: "2" level: 1
right left right left right
Node key: 5 value: "5" level: 2
left
Node key: a value: "a" level: 2
right
Node key: 4 value: "4" level: 1
left
Node key: 6 value: "6" level: 1
right left right left right
Node key: 8 value: "8" level: 1
left
Node key: b value: "b" level: 1
right left
Node key: 9 value: "9" level: 1
right left right left right