• No results found

Visualising Java Data Structures as Graphs

N/A
N/A
Protected

Academic year: 2021

Share "Visualising Java Data Structures as Graphs"

Copied!
21
0
0

Loading.... (view fulltext now)

Full text

(1)

Visualising Java Data Structures as Graphs

John Hamer

Department of Computer Science

University of Auckland

(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

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

(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

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) );

}

}

(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

Frame #1

LinkedList

size: 0

Entry

element: null

header

(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

Frame #2

LinkedList

size: 1

Entry

element: null

header

Entry

element: 100

(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

Frame #3

LinkedList

size: 2

Entry

element: null

header

Entry

element: 100

next

Entry

element: 101

previous

previous

next

next

previous

(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

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

(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

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" );

(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

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.).

(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

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.

(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

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;

(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

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,

(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

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

(14)

Visualising the Java data model

HashMap

size: 3

threshold: 8

loadFactor: 2.0

modCount: 3

table

Entry

key: three

value: 3

hash: -741826716

0

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

object’s node.

Object fields are shown as labelled

(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

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).

(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

The Full Monty

String x = "Hello";

String y = new String(x);

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

String

offset: 0

count: 5

hash: 0

0

String

offset: 0

count: 5

hash: 0

1

H

e

l

l

o

value

value

+

Useful in explaining the memory

consumption of substring

operations, or as an example of a

sharing data structure.

Clutters the visualisation.

Details are a distraction (e.g.,

(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

Hide the internal state

Hello

0

Hello

1

+

Visualisation respects reference semantics.

+

More compact.

Internal sharing is not shown.

Can be used with any object, by calling the

(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

Pretend it’s primitive

Hello

Hello

+

Most compact.

Visualisation contradicts reference

semantics.

Can be used with any object, by calling the

(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

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

(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

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

or OOP (but see, e.g., UMLGraph

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

)

Freely available from

(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: 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 Node key: 16 value: "16" level: 1 left Node key: 19 value: "19" level: 2 right Node key: 18 value: "18" level: 1 left Node key: 2 value: "2" level: 1 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 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
John Hamer, www.graphviz.org http://www.spinellis.gr/sw/umlgraph/)

References

Related documents

On the other hand, operating costs are incurred on a daily basis and are associated with the cost of production of material at plants, the handling of material at ware- houses

Long-term operation of Dukovany NPP New nuclear sources Stabilization abroad Renewable sources Customer orientation New Energy Performance and Entrepreneurship 1...

As well as in a lot of large Russian cities, such festivals as Museum Night, A Night at The Theater, etc. take place in Krasnoyarsk. However, this article refers to the..

designers are betting that the practice of highway traffic monitoring is poised for a dramatic change, one that will provide accurate, dependable measurement of the weight and

In conclusion, our case suggested that aggressive management of choledocholithiasis using ERCP and accompanied by percutaneous cholecystostomy can be carried out safely.

Any seaman who shall suffer personal injury in the course of his employment may, at his election, maintain an action for damages at law, with the right of trial

First, to develop a TP scale and establish the current state of Uganda’s tourism product; second, to establish the relationship between TPs of Uganda’s tourism product and