What is the difference between final, finally and finalize?

Asked By 7060 points N/A Posted on -
qa-featured

What is the difference between final, finally and finalize?

I cannot understand Could someone explain those function with example?

 

SHARE
Best Answer by mary_aivie
Best Answer
Best Answer
Answered By 0 points N/A #80458

What is the difference between final, finally and finalize?

qa-featured

Hi there,
 

The difference between final, finally and finalize () is given below.

Final – Constant Declaration

Finally – The finally block always executes in the existence of three blocks, except of system. exit (0) call. This proves that the finally block would be executed even if an unexpected exception is occurring but the final is also useful for more than just exception handling. It allows the programmer to avoid having cleanup code accidentally bypassed by a return, continue or break. By putting the cleanup code in a finally block there is a good practice even when no exception is anticipated.

Finalize ()
This method is helpful for raw objects collection. It is a method that is shown about the objects before an object is discarded by the raw objects collector, by allowing it to clean up its state. It should not be used to release non-memory resources and you do not have knowledge about when the raw objects collection is going to kick in to release these non-memory resources through the finalize () method.

After explaining the whole stuff I was thinking about to put it in another way, just forget Java.
Just take another example.
Final: I want a have a god and only the one I have seen is Tomy, I have never thought about another of such kind in my life. So this is final.

Finally
I am going for some shopping, it does not matter what I try and buy and what I cannot. Finally after paying bill I should drop my shopping cart in the proper place.

Answered By 0 points N/A #80459

What is the difference between final, finally and finalize?

qa-featured

We can use final keyword in java by three ways

Final Variable: It acts like a constant
Final Method: It cannot be override
Final Class: It cannot get in parts

Final is a keyword in Java. It is a constant and cannot be changed from its initiated value.

Finally () method is used for exception handling concept. The finally () block will be executed whether or not try block can be executed. It is use to close a file.

Finalize() is the one of the method provide by JAVA lib for raw objects/ data collection. Raw Data collection removes the space occupied by the unused variables, objects and other raw data.

Have this will be helpful for you.

Answered By 0 points N/A #80460

What is the difference between final, finally and finalize?

qa-featured

The Final is a keyword which is used for the following purposes.
Final variable use to cure the modification value
Final method cannot be transfer
Final class cannot be in parts

Examples

Finally is the block of code that is used with the try / catch block or try block if there will no catch associated with this try block. This is useful where you think that there must some code will be executed whether the exception is thrown out of not.

Finalize is a method that is called by JVM just before the performing the raw objects collection but this is not sure that this mother will be called or not. It depends upon the JVM. It is declared in the Object Class.

You can override the finalize () methed.

Related Questions