SlideServe
Menu
Préférences
© SlideServe · v2026

CPSC 233 Tutorial

stuart avatar
15 diapositives · 303 Views · Aug 04, 2014

This tutorial explores key concepts in Java programming, focusing on garbage collection, runtime objects, arrays, and linked lists. It explains how garbage collectors free memory by de-referencing objects that are no longer needed, and how the finalize method manages resources. The tutorial also covers the structure of arrays and provides examples of their implementation. In addition, it delves into linked lists, illustrating insertion and removal operations with graphical algorithms to enhance understanding. Perfect for students looking to master fundamental Java concepts.

CPSC 233 Tutorial - slide 1
01 / 15CPSC 233 Tutorial
1 / 17

Télécharger la présentation

CPSC 233 Tutorial
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  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