Visualising Java Data Structures as Graphs John Hamer Department of - - PowerPoint PPT Presentation

visualising java data structures as graphs
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

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

slide-2
SLIDE 2
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 2/21

The Idea

■ Student code calls the static method

Dot.drawGraph(whatever)

■ 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,

etc.) picture

■ Student views the sequence of pictures using a standard

viewer

slide-3
SLIDE 3
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 3/21

Example

public static void main( String[] args ) { List xs = new LinkedList( ); for( int i = 0; i < 4; i++ ) { Dot.drawGraph( xs ); xs.add( new Integer(i+100) ); } }

slide-4
SLIDE 4
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 4/21

Frame #1

LinkedList size: 0 Entry element: null

header next previous

slide-5
SLIDE 5
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 5/21

Frame #2

LinkedList size: 1 Entry element: null

header

Entry element: 100

next previous next previous

slide-6
SLIDE 6
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 6/21

Frame #3

LinkedList size: 2 Entry element: null

header

Entry element: 100

next

Entry element: 101

previous previous next next previous

slide-7
SLIDE 7
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 7/21

Frame #4

LinkedList size: 3 Entry element: null

header

Entry element: 100

next

Entry element: 102

previous previous

Entry element: 101

next previous next next previous

slide-8
SLIDE 8
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 8/21

Frame #4 coloured

LinkedList size: 3 Entry element: null

header

Entry element: 100

next

Entry element: 102

previous previous

Entry element: 101

next previous next next previous

Dot.Context ctx = Dot.defaultContext( ); ctx.setFieldAttribute( "next", "color=blue" ); ctx.setFieldAttribute( "previous", "color=red" );

slide-9
SLIDE 9
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 9/21

About GraphViz

■ GraphViz is a widely used, freely available graph drawing

program, developed at ATT; see www.graphviz.org

■ Layout is completely automatic and (generally) æsthetically

pleasing.

■ Text input for nodes and edges, with optional attributes

(colour, node shape, labels, fonts, etc.).

■ Output to a variety of formats (PNG, EPS, SVG, . . . )

slide-10
SLIDE 10
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 10/21

Related work

GraphViz

■ Brocard —Perl interface to GraphViz for

visualising data structures; also regular expressions, grammars, XML, call graph, profiling, . . . .

■ North & Koutsofios —visual debugger, vdbx

Visualisation

■ Thomas Naps’ Visualiser class. Canned

collection of visualisations: numeric arrays (bar, scattergram, data views), general arrays, stacks, queues, linked lists, binary trees, general trees, graphs, networks.

slide-11
SLIDE 11
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 11/21

Principles

■ 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

into the curriculum;

■ software must be reliable.

slide-12
SLIDE 12
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 12/21

Features of our tool

■ trivial to setup and easy to use (source < 600 lines); ■ active learning —students decide where to place the calls

to drawGraph, what to elide;

■ connects code with the Java data model; ■ usable on any Java program; no specific programming

conventions necessary;

■ allows “wrong” data structures to be viewed (as well as

correct ones);

■ configuration allows broad and precise elision of detail; ■ visualisations can be incorporated in reports, www pages,

and presentations.

slide-13
SLIDE 13
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 13/21

Overcoming student misconceptions

Java has a simple data model, right?

■ Strings are objects, but string constants look like primitive

values.

■ Assignment of objects is by reference, primitive types by

value.

■ Object arrays hold references, not values. ■ 2-dimensional arrays are constructed from 1-d arrays (is it

row or column order?)

■ Static fields are not part of any object. ■ Inheritance means objects are often not the same as their

declared types.

slide-14
SLIDE 14

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 14/21

Visualising the Java data model

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

juxtaposed.

■ Values in primitive arrays are shown

inline.

■ Object arrays just contain links. ■ Primitive fields are shown inside the

  • bject’s node.

■ Object fields are shown as labelled

arcs.

slide-15
SLIDE 15
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 15/21

Degrees of faithfulness

Three different views of String

■ Show the full internal state of String. ■ Acknowledge String is an object, but hide the internal

state.

■ Pretend String is a primitive value (not an object).

These views apply to any object, not just String.

slide-16
SLIDE 16
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 16/21

The Full Monty

String x = "Hello"; String y = new String(x); Dot.drawGraph( new String[]{ x, y } );

String

  • ffset: 0

count: 5 hash: 0 String

  • ffset: 0

count: 5 hash: 0

1

H e l l

  • value

value

+ Useful in explaining the memory consumption of substring

  • perations, or as an example of a

sharing data structure. − Clutters the visualisation. − Details are a distraction (e.g., explaining hash).

slide-17
SLIDE 17
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 17/21

Hide the internal state

Hello Hello

1

+ Visualisation respects reference semantics. + More compact. − Internal sharing is not shown.

■ Can be used with any object, by calling the

toString method.

slide-18
SLIDE 18
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 18/21

Pretend it’s primitive

Hello Hello + Most compact. − Visualisation contradicts reference semantics.

■ Can be used with any object, by calling the

toString method.

slide-19
SLIDE 19
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 19/21

Limitations and future work

■ GraphViz has limited support for node shapes, label

placement, . . . .

■ Graphs of, e.g., Java AWT components, can be immense.

Drawing even a simple Button will bring in every interface component!

■ Work in progress on integration with a debugger (Jacob

Tseng). Extended a Java IDE debugger with a “draw”

  • command. Graphs are updated at each breakpoint.

■ Also, “draw” command extension to the BeanShell (an

interactive Java interpreter), provided by a first-year student.

■ More elision controls. ■ Experimental features for dynamically selecting attributes

(e.g., red nodes in a red-black tree are displayed in red).

■ Interactive graphs —select a node and expand or elide.

slide-20
SLIDE 20
  • The Idea
  • Example
  • About GraphViz
  • Related work
  • Principles
  • Features of our tool
  • Overcoming student misconceptions
  • Visualising the Java data model
  • Degrees of faithfulness
  • The Full Monty
  • Hide the internal state
  • Pretend it’s primitive
  • Limitations and future work
  • Summary and conclusions
  • A view of an “Arne” Tree

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 20/21

Summary and conclusions

■ Light-weight, general purpose visualisation tool for Java. ■ Useful in elucidating the Java data model, especially

reference semantics.

■ Less suitable for classical array data structures (c.f., Naps),

  • r OOP (but see, e.g., UMLGraph

http://www.spinellis.gr/sw/umlgraph/)

■ Freely available from

http://www.cs.auckland.ac.nz/~j-hamer

slide-21
SLIDE 21

John Hamer, January 15, 2004 ACE’2004—Visualising Java Data Structures as Graphs – p. 21/21

A view of an “Arne” Tree

{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