Final Finally Finalize

View previous topic View next topic Go down

Final Finally Finalize

Post  Admin on Wed Aug 24, 2011 6:13 pm

Final
When applied to a variable (primitive): The value of the variable cannot change.

When applied to a variable (reference): The reference variable cannot point to any other ob- ject on the heap.
When applied to a method: The method cannot be overridden. When applied to a class: The class cannot be subclassed. Finally
There is an optional ␣nally block after the try block or after the catch block. Statements in the ␣nally block will always be executed (except if JVM exits from the try block). The ␣nally block is used to write the clean up code.
Finalize
This is the method that the JVM runs before running the garbage collector.

Admin
Admin

Posts : 131
Join date : 2011-08-16

View user profile http://codefornongeek.forumotion.com

Back to top Go down

Re: Final Finally Finalize

Post  Admin on Mon Aug 29, 2011 10:28 pm

The finalize () Method



Sometimes an object will need to perform some action when it is destroyed. For example, if an object is holding some non-java resource such as a file handle or window character font, then you might want to make sure these resources are freed before an object is destroyed. To handle such situations, java provides a mechanism called finalization. By using finalization, you can define specific actions that will occur when an object is just about to be reclaimed by the garbage collector.



To add a finalizer to a class, you simply define the finalize() method. The java run time calls that method whenever it is about to recycle an object of that class. Inside the finalize() method you will specify those actions that must be performed before an object is destroyed. The garbage collector runs periodically, checking for objects that are no longer referenced by any running state or indirectly through other referenced objects. Right before an asset is freed, the java run time calls the finalize() method on the object.



The finalize() method has this general form:



protected void finalize()

{

// finalization code here

}



Here, the keyword protected is a specifier that prevents access to finalize() by code defined outside its class.

Admin
Admin

Posts : 131
Join date : 2011-08-16

View user profile http://codefornongeek.forumotion.com

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum