final keyword
class
On a class it means you forbid to have a child class extending yours.
public final class finalClass
Attribute/Field
final MyObject value = new MyObject()
means you won't be able to modify the instance of the object.
value = xxxx
won't be allowed, but you still can modify the object itself value.field = "xxx";
Method
When you use final
on a method, that means you'll forbid child classes that extends your class to override this method.
public final void finalMethod()
It can also be used on arguments, that means you don't allow other to modify the instance of the object you give.
public void myMethod(final MyObject myObject)
The end user won't be able to do myObject = ...
Finally block
finally
block has nothing to do with final
, it's used when catching Exception to ensure a part of code will be ran, wherever there is an exception or not.
try { ...}
catch {} // Optional
finally { // Code that will be ran, exception or not being thrown}
Finalize method
It's called on every object when it's destroyed (usually garbage collected).