Basic HTML version of Foils prepared May 12 1996

Foil 56 Class Finalizers

From CRPC Lectures on Java Language Applets Graphics CRPC Annual Meeting Tutorial -- May 14,1996. by Geoffrey C. Fox


1 Any class can have an optional finalizer that will perform any necessary clean-up needed when garbage collector (which is automatic in Java) tries to delete object and free-up resources it uses
2 An example is given for an object that uses an I/O stream and needs to close it on termination
3 protected void finalize() {
  • try {
    • file.close();
  • } catch (Exception e) { /* Catches ANY exception */
  • }
4 }
5 Earlier one might have set this up with syntax such as that on next foil

in Table To:


Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sun Dec 14 1997