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

What are java packages? What's the significance of packages?

0 Answers  


What is the use of conditional statement?

0 Answers  


Can a private method be declared as static?

0 Answers   Global Logic,


Explain about GridBag Layout?

1 Answers  


what is abstract class in Java?

0 Answers   Hexaware, Syntel,






What is executor memory?

0 Answers  


Why stringbuilder is not thread safe in java?

0 Answers  


when,where and how to use abstract class and interface

2 Answers  


Can you have a constructor in abstract class?

18 Answers   HCL,


what do you mean by classloader?

0 Answers  


what is the difference b/w static and final methods?

1 Answers  


how to create daemon thread in java?

0 Answers  


Categories