what are the differences between final,finally,finalize
methods?
Answers were Sorted based on User's Feedback
Answer / jayakrishnan.p
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 ? | 168 Yes | 17 No |
Answer / ambika
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 ? | 96 Yes | 18 No |
Answer / ravikiran
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 |
Answer / sunil
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 |
Answer / thennavan.m
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 |
Answer / mukesh makwana
* 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 |
Answer / vibhor bhatnagar
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 |
Answer / saurabh nigam
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 |
Answer / ravi
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 |
Answer / boomiraj
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 |
What are the two environment variables that must be set in order to run any java programs?
Can we have static methods in an interface?
What is meant by 'Class access modifiers'?
Can we execute a program without main?
Why do we use bufferedreader?
What types of index data structures can you have in java?
A class can be a subclass of itself?
How to instantiate static nested classes in java?
What happens when I use / and % with a negative numerator?
What is the purpose of using bufferedinputstream and bufferedoutputstream classes?
What is the difference between the program and the process?
What is meant by singleton class?