what are the differences between final,finally,finalize
methods?
Answer Posted / 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 |
Post New Answer View All Answers
What is an image buffer?
What is java oops?
Is a case study a method or methodology?
What is the difference between path and classpath variables?
how we can use debug in myeclipse 6.0 in order solve the problems that exist in our program when there are 900 to 1000 pages in a web application
What is a priority queue java?
State one difference between a template class and class template.
Say you want to store the information about a number of pets in an array. Typical information that you could store for each pet (where relevant) would be • Breed of animal • Animal's name • Its birth date • Its sex • Whether it has been sterilised or not • When it is due for its next inoculation • When it last had its wings clipped For each type of pet (eg. dog, cat or bird) you would typically define a class to hold the relevant data. Note: You do not need to implement these classes. Just answer the following questions. 3.1.1 What would be the advantage of creating a superclass (eg. Pet) and declaring an array of Pet objects over simply using an array of Objects, storing each of the instances of the different pet classes (eg. Dog, Cat or Bird) in it? 3.1.2 Would you define Pet as a class or as an interface? Why? (2) (2)
Why do we create public static method in java?
Can abstract class have private constructor?
What are class members by default?
What is java literals?
What is jrmp?
What is the difference between Java1.4 and Java1.5
Can you sort a string in java?