File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes From mIND q TEST some ques Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "From mIND q TEST some ques" Watch "From mIND q TEST some ques" New topic

From mIND q TEST some ques

sunilkumar ssuparasmul
Ranch Hand

Joined: Dec 13, 2000
Posts: 142
Which of the following statements about Java's garbage collection are true?
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.
///CODE 2
void myMethod()
{ try
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?
plz clarify

"Winners don't do different things
They do things differently"

"Winners don't do different things<br /> They do things differently"
anil bisht
Ranch Hand

Joined: Nov 04, 2000
Posts: 81
as for the first Q i am not sure ..
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
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
Using the Runtime.gc() method, you can indeed invoke the garbage collector. However, it is not guranteed that the garbage collector will actually run and do its job after such a call.
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.

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Jini Varghese
Ranch Hand

Joined: Dec 06, 2000
Posts: 58
Hi ,
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...
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
Yes, you got it right. So the answer (a) in the original question is indeed true.
Jini Varghese
Ranch Hand

Joined: Dec 06, 2000
Posts: 58
jQuery in Action, 3rd edition
subject: From mIND q TEST some ques
jQuery in Action, 3rd edition