ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Java Related >> Java J2EE >> Core Java
 
 


 

 
 Core Java interview questions  Core Java Interview Questions (1722)
 Advanced Java interview questions  Advanced Java Interview Questions (331)
 Swing interview questions  Swing Interview Questions (44)
 EJB interview questions  EJB Interview Questions (134)
 Servlets interview questions  Servlets Interview Questions (255)
 Struts interview questions  Struts Interview Questions (196)
 JDBC interview questions  JDBC Interview Questions (187)
 JMS interview questions  JMS Interview Questions (9)
 SunOne interview questions  SunOne Interview Questions (3)
 J2EE interview questions  J2EE Interview Questions (71)
 Weblogic interview questions  Weblogic Interview Questions (147)
 Websphere interview questions  Websphere Interview Questions (14)
 Java Networking interview questions  Java Networking Interview Questions (20)
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions (87)
Question
what are the differences between final,finally,finalize 
methods?
 Question Submitted By :: Core-Java
I also faced this Question!!     Answer Posted By  
 
Answer
# 1
final is used for making a class no-subclassable, and making
a member variable as a constant which cannot be modified.
finally is usually used to release all the resources
utilized inside the try block. All the resources present in
the finalize method will be garbage collected whenever GC is
called. Though finally and finalize seem to be for a similar
task there is an interesting difference here.This is because
the code in finally block is guaranteed of execution
irrespective of occurrence of exception, while execution of
finalize is not guarenteed.finalize method is called by the
garbage collector on an object when the garbage collector
determines that there are no more references to the object.
 
Is This Answer Correct ?    167 Yes 16 No
Jayakrishnan.p
 
Answer
# 2
final is a keyword.its constant.it cant be changed from its
initiated value.

finally() method used exception handling concept.finally()
block will execute whether or not try block can be execute.
its used to close a file.

finalize is used when an object is just before deleted,it
can be used in garbage collection.
 
Is This Answer Correct ?    94 Yes 18 No
Ambika
 
 
 
Answer
# 3
final variable:Acts like a constant
final method:cann't be overrided
final class:cann't get subclassed

finally is a block which is used to conserve the resource
irrespective of the exception being caught or not

finalize is the method which is used to save tje resources
before the unused object get garbage collected.
 
Is This Answer Correct ?    55 Yes 6 No
Ravikiran
 
Answer
# 4
final variable is a constant.
final method cann't be overrid.
final class cann't be subclassed.

finally is a block usually used to release all the
resources utilized inside the try block such as to free
resources like stream objects, to close sockets .The code
in finally block is guaranteed of execution
irrespective of occurrence of exception catched/uncatched.

finalize() is never run more than once on any object.
finalize method is called by the garbage collector on an
object when the garbage collector determines that there are
no more references to the object.
 
Is This Answer Correct ?    30 Yes 6 No
Sunil
 
Answer
# 5
final is a Modifier

finally is a closed Exception Statement

finalize is method{remove the memory resource before call
the garbage collection}
 
Is This Answer Correct ?    20 Yes 11 No
Thennavan.m
 
Answer
# 6
* 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 ?    14 Yes 5 No
Mukesh Makwana
 
Answer
# 7
Final :
final is a Modifier
final variable is a constant.
final method cann't be overrid.
final class cann't be subclassed.

Finally :
The finally clause is used to provide the capability to
execute code no matter whether or not an exception is
thrown or caught.

Finalize:
The purpose of finalization is to give an unreachable
object the opportunity to perform any cleanup processing
before the object is garbage collected. OR An object’s
finalize() method may only be invoked once by the garbage
collector.
 
Is This Answer Correct ?    15 Yes 13 No
Vibhor Bhatnagar
 
Answer
# 8
The keyword "final" in Java is used in different ways
depending on the context. We can have final methods, final
classes, final data members, final local variables and
final parameters. A final class implicitly has all the
methods as final, but not necessarily the data members. A
final class may not be extended; neither may a final method
be overridden.
Final primitive data members cannot be changed once they
are assigned, neither may final object handle data members
(Vector, String, JFrame, etc.) be reassigned to new
instances, but if they are mutable (meaning they've got
methods that allow us to change their state), their
contents may be changed.
A final class cannot be subclassed. This is done for
reasons of security and efficiency. Accordingly, many of
the Java standard library classes are final,


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

Final is used for making a class no-subclass able, and
making
a member variable as a constant which cannot be modified.
Final is a Modifier


Finally is usually used to release all the resources
Utilized inside the try block. All the resources present in
The finalize method will be garbage collected whenever GC
is Called. Finally is a closed Exception Statement

Though finally and finalize seem to be for a similar Task
there is an interesting difference here. This is because
The code in finally block is guaranteed of execution
Irrespective of occurrence of exception, while execution of
Finalize is not guarenteed.finalize method is called by the
Garbage collector on an object when the garbage collector
Determines that there are no more references to the object.
Finalize is method {remove the memory resource before call
The garbage collection}
 
Is This Answer Correct ?    11 Yes 10 No
Saurabh Nigam
 
Answer
# 9
A "final" method or variable is one that can't be overridden
- you can define a method as final within a class to ensure
that any extensions to the class don't replace it.

If you add a "finally" block onto the end of a try / catch
exception handler, you're defining a block of code that will
be run if the try is entered, even if problems occur and
your method returns from within a catch rather than continuing.

A "finalize" method is your destructor method - code that's
run to clean up objects that are no longer required. For
example, objects which are memory cached would be flushed
back to the disc in your finalize.
 
Is This Answer Correct ?    8 Yes 7 No
Ravi
 
Answer
# 10
Final:It cant change during execution . Cant be extended.
Finally:It is execute even if execution may (or) may not
come.It must be execute if your declare in program.Can
block finally using System.err(0);statement.
Finalize():It is a garbage collector.
 
Is This Answer Correct ?    1 Yes 0 No
Boomiraj
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
How to synchonise HashMap IBM 3
what is hashmap& hashtable with example? CTS 1
without using arthematic operation ,how can you write the logic for adding/substraction/multiplication? Wipro 7
Name the package that always imported by default?   4
whats is the use of final,in which situation final can be used in the application? DNS 2
Package1 and Package2 both have a method name lets say "methodA" with different implementation. When I import both the packages in a java class how can I use both the methods? Ericsson 7
Can u overload main()method.Give with example. IBM 6
How many ways can an argument be passed to a subroutine? Technological-University-of-the-Philippines 3
waht You know about thread programming?   1
Is java supports multiple inheritance? explain? Inforica 12
What is the need to implement Serializable interface (with no methods) for objects which are to be serialized ? We can write our own functionality which writes objects to streams then why we need to implement and tell JVM that which objects can be serialized. iFlex 6
What is lazy activation? CMC 2
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright © 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com