a) The garbage collector can be invoked explicitly using a Runtime object.
b) The finalize method is always called before an object is garbage collected.
c) Any class that includes a finalize method should invoke its superclass' finalize method.
d) Garbage collection behavior is very predictable.
MY answer were b,c but it says "a" also ? how can u invoke GC.
catch( NullPointerException npex )
System.out.println( "NullPointerException thrown " );
catch( Exception ex )
System.out.println( "Exception thrown " );
System.out.println( "Done with exceptions " );
System.out.println( "myMethod is done" );
the choice were
a) "NullPointerException thrown"
b) "Exception thrown"
c) "Done with exceptions"
d) "myMethod is done"
e) Nothing is printed
my ans were b,c but answer says "d" also how?
"Winners don't do different things
They do things differently"
can anyone answer .. because we can invooke GC but its not sure that it will run at that time or not ?? does the answer mean this.
and for the second part..
if an exception occurs, and it is caught
1) then all the statements below the statement where Ex occured are skipped
2) it goes to the catch block and
3) runs finally and come out of the try block
4) and then it executes the rest of the code after the try block
but if it is not caught then
1) all the statements below the statement where Ex occured are skipped
2) it goes to the finally block and executes it and comes out of the function. ignoring the statements after teh try catch block
Here's the excerpt of the method from API documentation. Pay attention to the text in bold
public void gc()
Runs the garbage collector. Calling this method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the Java Virtual Machine has made its best effort to recycle all discarded objects.
This description should not be intepreted at face value. Infact the very first statement "Runs the garbage collector" is not semantically accurate and is quite misleading. Since the garbage collection is dependant on the implementation, it is perfectly legal ( and acceptable ) if some implementations choses to turn ignore to explicit requests for running the GC. In such a case, the call to System.gc() or Runtime.gc() will have no effect.
So, For q.1, is the statement 1 true or false ?. What I understood from the above messages is this : you can invoke GC, but it does not guarantee that it will run, right ?
Thanks in advance...