Master List of Java Questions: What Is Exception ?
Master List of Java Questions: What Is Exception ?
1. What is Exception ?
For every project you implement you need to have a project dependent exception
class so that objects of this type can be thrown so in order to cater this kind of
requirement the need for user defined exception class is realized.
for example:
As per the design decision Java does not support pointers explicitly.This greatly
reduces the burden of dynamic memory management while coding from
programmers.Though programmers dynamically allocate memory while coding
but they need not worry about deallocating this memory.The automatic garbage
collection feature of Java collects dangling references of objects though it has a
trade off on performance as programmer managed memory management will be
efficient as compared to JVM driven automatic garbage collection.
5. Does garbage collection guarantee that a program will not run out of memory?
Garbage collection does not guarantee that a program will not run out of memory.
As garbage collection is JVM dependent then It is possible for programs to use
memory resources faster than they are garbage collected.Moreover garbage
collection cannot be enforced,it is just suggested.Java guarantees that the finalize
method will be run before an object is Garbage collected,it is called by the
garbage collector on an object when garbage collection determines that there are
no more references to the object.
The garbage collection is uncontrolled, it means you cannot predict when it will
happen, you thus cannot predict exactly when the finalize method will run. Once a
variable is no longer referenced by anything it is available for garbage
collection.You can suggest garbage collection with System.gc(), but this does not
guarantee when it will happen.
-Use of System.exit()
-The death of thread
-Turning off the power to CPU
-An exception arising in the finally block itself