1 / 15

CPSC 233 Tutorial

CPSC 233 Tutorial. Xin Feb 7, 2011. Assignment 3. Due on Friday, Feb 18 Garbage collection Runtime object Array Linked list/chain. Garbage collector. In Foo f = new Foo (); , f is a “reference” to the object

stuart
Download Presentation

CPSC 233 Tutorial

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CPSC 233 Tutorial Xin Feb 7, 2011

  2. Assignment 3 • Due on Friday, Feb 18 • Garbage collection • Runtime object • Array • Linked list/chain

  3. Garbage collector • In Foof = new Foo();, f is a “reference” to the object • If later you write f = new Foo(); or f = null; the previously created object is not referenced any more • It becomes a garbage • Java will use a collector to free the memory occupied by garbage • When a garbage is freed, a finalize method is called if you implement it for the class • finalize() is used to free resources, such as files and network connections

  4. Runtime • An object allows an application to interface with the running environment • getRuntime() • return the current runtime. • gc() • Run the garbage collector. • runFinalization() • Runs the finalization methods of any objects pending finalization.

  5. Runtime -- example class Runtime_foo { public void finalize () { System.out.println("going"); } } class Runtime_driver { public static void main (String [] args) { Runtime_foof = new Runtime_foo (); f = null; Runtime rt = Runtime.getRuntime(); rt.gc(); // calls finalize rt.runFinalization(); } }

  6. Array • A structure with a fixed number of elements • int [] arr = new int[10]; • arr[0] = 100;

  7. Array – an example public class StringArray { public static void main (String [] args) { String [] myStringArray = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; for (inti = 0; i < myStringArray.length; i++) { System.out.println(myStringArray[i]); } } }

  8. Head Data Data Data Ptr Ptr Ptr Pointer/reference (connector) Data (data) Node List Elements: Nodes

  9. LIST NULL NEW ELEMENT List Operations: Linked Lists (Insertion) • Graphical illustration of the algorithm: Temp

  10. LIST NULL NEW ELEMENT List Operations: Linked Lists (Insertion: 2) • Graphical illustration of the algorithm: Temp

  11. List Operations: Linked Lists (Insertion: 3) • Graphical illustration of the algorithm: Temp LIST NULL NEW ELEMENT

  12. List Operations: Linked Lists (Removing Elements) • Graphical illustration of the algorithm Remove LIST NULL

  13. List Operations: Linked Lists (Removing Elements: 2) • Graphical illustration of the algorithm Remove LIST NULL Previous Current

  14. List Operations: Linked Lists (Removing Elements: 2) • Graphical illustration of the algorithm Remove LIST NULL Previous Current Node to be removed has been bypassed (effectively deleted from the list)

  15. Example -- Book Inventory • UML

More Related