final finally finalize are keywords in Java, These keywords are used in exception handling.
final in Java
final is the modifier in Java applicable for classes, methods, and variables. If a class is declared as final then we can’t extend that class in other words we can’t create a child class for the final class i.e., inheritance is not possible with the final class.
If a method is final then we can not override that method.
If a variable declares as final then we can not update the value of a variable.
finally in Java
finally is a block always associate with try catch to maintain clean up code.
try{
// Risky code
}
catch(Exception e)
{
//Handling exception
}
finally
{
// cleanup code
}
Irrespective of whether an exception is raised or not, whether an exception is handled or not finally block will be executed every time.
finalize in Java
finalize is a method always invoked by a garbage collector just before destroying an object to perform the cleanup activity. Once finalize method is completed, imideatiley garbage collector destroys that object.
Note-
finally, the block is responsible to perform cleanup activities related to the try-catch block, whereas finalize method is responsible to perform cleanup activities related to the object.
Similar Java Tutorials
- Odd Even in Java
- Fibonacci Series Java
- Switch statements in Java
- For loop in Java
- While loop in Java
- Do while loop in Java
- Import statement in Java
- Abstract modifier in Java
- Strictfp modifier in Java
- Final variable in Java
- Adapter Class in Java
- Method signature in Java
- Method overloading in Java
- Has A Relationship
- Inheritance in Java
- Encapsulation in Java
- Abstraction in Java
- Data Hiding in Java
- Interface vs abstract class
- Method Overriding in Java
- Method Overloading in Java
- Coupling in Java
- Method to print exception information in Java
- Exception Handling by Using try-catch in Java
- Checked Exception vs Unchecked Exception
- Exception Hierarchy in Java
- Java Exception Handling Interview Questions
6 thoughts on “final finally finalize in java”