Java / Exception
Difference between final, finally and finalize in Java.
final keyword is used to make a variable or a method or a class as "unchangeable".
Final variable: A variable which is declared as final, its value cannot be changed once it is initialized.
A final method declared as final can not be overridden or modified in the subclass.
A final class cannot be extended.
finally block is used for exception handling along with try and catch blocks. finally block is always executed whether an exception is raised or not and raised exception is handled or not. Most of the time, this block is used to close the resources like database connection, I/O resources.
finalize method is a protected method of java.lang.Object class. It is inherited by every class you create in Java. This method is called by garbage collector thread before an object is removed from the memory. finalize() method is used to perform some cleanup operations on an object before it is removed from the memory.
More Related questions...