Finally is a block that is used in conjunction with the try-catch-finally or the try-finally blocks for exception handling. Any lines of code residing under the finally block are executed even if there is an Exception inside the try block.
For example, Stream close or DbConnection close statements.
db.open();
try {
// some statements
}
catch(Exception ex) {
// handle exception
}
finally {
db.close();
}
Finalize is a method in conjunction with the Garbage Collection. The method is called by the GC to cleanup resources before the object is destroyed.
public class MyClass {
~MyClass() {
// any custom release operations
}
}