what are the differences between final,finally,finalize
methods?

Answers were Sorted based on User's Feedback



what are the differences between final,finally,finalize methods?..

Answer / brijendra(xavient)

1-Final:Java have final class,finalmethod and
finalvariables.
*Finalclass can not be extended and the variables under the
final class can not be change.
*Finalvariables can not be changed.
*finalmethods can not be override or overriden.

2-Finally-Finally is a block which is used for catching the
uncaught exception which not handled by try block.

3-Finalize()- finalize method helps in garbage collection.A
method,that is invoked before an object is discarded by the
garbage
collector, allowing it to clean up its state

Is This Answer Correct ?    1 Yes 0 No

what are the differences between final,finally,finalize methods?..

Answer / somi

Final:- It is used in the following three cases:
If the final keyword is attached to a variable then the variable becomes constant i.e. its value cannot be changed in the program.
If a method is marked as final then the method cannot be overridden by any other method.
If a class is marked as final then this class cannot be inherited by any other class.
Finally:- If an exception is thrown in try block then the control directly passes to the catch block without executing the lines of code written in the remainder section of the try block. In case of an exception we may need to clean up some objects that we created. If we do the clean-up in try block, they may not be executed in case of an exception. Thus finally block is used which contains the code for clean-up and is always executed after the try ...catch block.

Finalize:- It is a method present in a class which is called before any of its object is reclaimed by the garbage collector. Finalize() method is used for performing code clean-up before the object is reclaimed by the garbage collector.

Is This Answer Correct ?    1 Yes 0 No

what are the differences between final,finally,finalize methods?..

Answer / ramudu

final – constant declaration.
finally – The finally block always executes when the try block exits, except System.exit(0) call. This ensures that the finally block is executed even if an unexpected exception occurs. But finally is useful for more than just exception handling — it allows the programmer to avoid having cleanup code accidentally bypassed by a return, continue, or break. Putting cleanup code in a finally block is always a good practice, even when no exceptions are anticipated.
finalize() – method helps in garbage collection. A method that is invoked before an object is discarded by the garbage collector, allowing it to clean up its state. Should not be used to release non-memory resources like file handles, sockets, database connections etc because Java has only a finite number of these resources and you do not know when the garbage collection is going to kick in to release these non-memory resources through the finalize() method.

Is This Answer Correct ?    1 Yes 0 No

what are the differences between final,finally,finalize methods?..

Answer / raghavendra

final key word is a modifier,and you cant perform any
modifications
finally : finally is used one type exception.suppose any
exception is generated,closed entire program suddenly,so
damage the remain information.overcome this disadvantage
introduce the finally key word.you write any information in
finally block,the information is successfully executed
finalize:this is one type of garbage collector,this key can
be used to collected unused memory

Is This Answer Correct ?    5 Yes 6 No

Post New Answer

More Core Java Interview Questions

How listener identify that the event came from a particular object?

0 Answers  


What is difference between fileinputstream and filereader in java?

0 Answers  


what is a package?

11 Answers  


What is JIT ?

4 Answers   Satyam,


Why set do not allow duplicates in java?

0 Answers  






Why are the methods of the math class static?

0 Answers  


Explain about the performance aspects of core java?

0 Answers  


Can we sort array in java?

0 Answers  


How destructors are defined in java?

0 Answers  


What is static block?

0 Answers  


Can subclass overriding method declare an exception if parent class method doesn't throw an exception?

0 Answers  


Can an interface be final?

0 Answers  


Categories