Showing posts with label FINALIZE. Show all posts
Showing posts with label FINALIZE. Show all posts

Thursday 14 January 2016

Difference between final, finally and finalize in java


final -
final is a keyword.
When a variable declared as final should be initialized only once and it cannot be changed.
In case of classes, final classes cannot be extended
In case of methods, final methods cannot be overridden.


finally -
finally is a block
finally is used in exception handling, is used to place code that are important and it will be executed whether the exception is handled or not.The finally block always executes when the try block exits. This ensures that the finally block is executed even if an unexpected exception occurs.


finalize -
finalize is a method.
Before an object is garbage collected, the run time system calls its finalize() method. That means this method used for clean up processing before object is garbage collected

Wednesday 22 January 2014

The Object class in java

what are the methods define object in java

The object class:


There is one special class, Object, defined by Java. All other classes are subclasses of Object.That is, Objectis a superclass of all other classes. This means that a reference variable of type Object can refer to an object of any other class. Also, since arrays are implemented as classes,a variable of type Object can also refer to any array.

Monday 20 January 2014

Using finalize() method in java

The finalize() method:


finalize method in java is a special method much like main method in java. finalize() is called before Garbage collector reclaim the Object, its last chance for any object to perform cleanup activity i.e. releasing any system resources held, closing connection if open etc.The intent is for finalize() to release system resources such as open files or open sockets before getting collected.