CS 123 - Programming Assignment 3

In this assignment you will draw Java memory maps. Download this zip file and un-zip it. In the zip file there is a copy of this web page, which you can read in your browser, and a number of other files that you need for this assignment. This assignment is due Monday, September 28.

In the zip file is a document called JavaMemoryMapExample.svg. This is an image file of a memory map for the following DrJava Interaction Pane session, which makes use of the two Java classes posted to the course web site on Wednesday, September 9.

   > SimpleClassWithState obj1
   > SimpleClassWithState obj2
   > obj1 = new SimpleClassWithState()
   > obj2 = new SimpleClassWithState()
   > obj1.increaseState()
   > obj1.increaseState()
   > obj2.increaseState()
   > ClassVsObjectMethods.A()
   > ClassVsObjectMethods x
   > double pi = 3.14
The image is a picture of Java's memory after executing the above ten statements. Your assignment is to draw similar memory maps of Java's memory after the execution of the code fragments given below.

Draw a map of Java's memory after the execution of the following code (in, for example, DrJava's interactions pane). Use these definitions for Class1 and Class2. Be sure that your memory map includes the (final) values of all the object and class variables.

   > Class1 ref1 = new Class1()
   > Class1 ref2 = new Class1()
   > Class2 ref3 = new Class2()
   > int x = 5
   > ref1.methodC(x)
   > ref2.methodC( ref1.methodB() )
   > Class1 ref4 = ref1
   > ref4.methodC( ref4.methodA() )
   > ref3.method1( Class2.method2() )
   > ref1.methodC( Class1.methodA() )

Draw another map of Java's memory after the execution of the following code. Assume that Java's memory is empty when this code begins executing. Use the same definition for Class1 as above. When you draw the memory map, assume that all non-referenced objects have been garbage collected (so you should not include in your drawing any non-referenced objects). Be sure that your memory map includes the (final) values of all the object and class variables.

   > Class1 obj1 = new Class1()
   > Class1 obj2 = new Class1()
   > Class1 obj3 = new Class1()
   > Class1 obj4 = new Class1()
   > obj4.methodA()
   > obj4 = obj3
   > obj1.methodC( obj1.methodB() + obj4.methodA() )
   > obj2.methodC(1000)
   > obj2 = obj4
   > obj4.methodC( obj2.methodB() )

You need to draw your memory maps using some kind of drawing tool. Included in the zip file is a folder called svg-edit-2.3. Open that folder and double click on the file svg-editor.html. That will open a simple, browser based, diagram editor called SVG-edit (written in JavaScript). You can use this editor to create drawings that are saved as svg (Scalable Vector Graphics) files, which can be viewed by a web browser. This is the editor that I used to create the example memory map. You can also use this editor directly over the Internet using the following URL.

http://svg-edit.googlecode.com/svn/tags/stable/editor/svg-editor.html

If you are familiar with some other drawing tool and would rather use it, feel free to. Just send me your drawings in either the svg, png, or pdf format. If you are not familiar with any drawing tools and would like to experiment with something more powerful than SVG-edit, try the free, open source, program Dia. Just download the following zip file, unzip it, and look for dia.exe in the bin subfolder.

http://sourceforge.net/projects/dia-installer/files/dia/0.95/dia-win32-binaries-0.95.zip/download

Turn in a zip file called CS123Hw3Surname.zip containing your diagrams. Please be sure to include your name in each of your diagrams, so that I know who they belong to after I print them out. Each of your diagrams should fit on a single page of paper. This assignment is due Monday, September 28.


Return to the main homework page.
Return to the CS 123 home page.


compliments and criticisms