• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MindQ q.no.37,42,45

 
Alokesh Phukan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Friends,
These q's are from the MindQ Test
45. Which methods does java.lang.Math include for trigonometric computations?
a) sin()
b) cos()
c) tan()
d) aSin()
e) aCos()
f) aTan()
g) toDegree()
Ans given: a,b,c
Doubt: are aSin, aCos, aTan not trigonometric computations ?
42. Which method below can change a String object, s ?
a) equals( s )
b) substring( s )
c) concat( s )
d) toUpperCase( s )
e) none of the above will change s
Ans given:e
Doubt:What is it testing? Strings being immutable or the method calls ?
37. 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.
Ans given:a,b,c
Doubt: b?. finalize won't be called more than once for an object.(i.e what if it has failed once??)
Would be great if you could resolve these doubts.
Thanking in advance,
Alokesh
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
45. Got you on case! There is no such method as aCos, aTan, aSin. They are acos, asin, atan.
42. Strings are immutable so no method can change them.
 
Haining Mu
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
45. Which methods does java.lang.Math include for trigonometric computations?
a) sin()
b) cos()
c) tan()
d) aSin()
e) aCos()
f) aTan()
g) toDegree()
Ans given: a,b,c
Doubt: are aSin, aCos, aTan not trigonometric computations ?

asin, acos,atan are, but not the ones with CAPITAL letters.

42. Which method below can change a String object, s ?
a) equals( s )
b) substring( s )
c) concat( s )
d) toUpperCase( s )
e) none of the above will change s
Ans given:e
Doubt:What is it testing? Strings being immutable or the method calls ?

both. Because all those methods will not change string 's'. Some of them construct and return new ones, but the content of string object which 's' referenced to never changed.
 
Alokesh Phukan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Thomas, Haining !
Silly of me to not notice the case.
So I gather my doubts on Q 37 are valid ?
Regards
Alokesh
 
yaeger rosenberg
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question about the last of the three? first, when you invoke gc() don't you do it as System.gc() or Runtime(?).gc(), so you are not really invoking it from a runtime OBJECT (it looks like a static invocation)?
Also, I don't really understand (and I can't get to the SUN site right now): when you make a call to gc(), are you guaranteed that the garbage collector will run? The wording of response a. "the garbage collector can be invoked explicitly" sounds like you are forcing it to run. Is it true that a call to gc() forces the garbage collector to run, but does not guarantee it will collect anything, or does a call to gc() suggest that the collector be run? I would have selected b and c. Is the response a. even talking about a call to gc()? Is a. just an ambiguous answer, and I am worrying too much?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say that the question is poorly worded.
------------------
Tom - SCJP --- Co-Moderator of the Programmer Certification Forums
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can explicitly invoke the garbage collector using System.gc() or Runtime.getRuntime().gc() BUT there is no guarantee the gc will run.
The finalize() method of any object will only be called once by the garbage collector; even if it fails, the gc will never call it again; however, you can explicitly invoke finalize() as often as you like.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder, is finalize() part of the certification? The objectives for garbage collection state, "State the behavior that is guaranteed by the garbage collection system, and write code that explicitly makes objects eligible for collection." RHE makes no mention of finalize(). I only had one gc question and it wasn't about finalize().
------------------
Tom - SCJP --- Co-Moderator of the Programmer Certification Forums
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not really part of the gc objective; but a question on finalize() could come up in relation to java.lang as it's defined in java.lang.Object; so doesn't hurt to be familiar with it.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am wondering if anyone has ever had a finalize() question. RHE doesn't mention the topic at all.
------------------
Tom - SCJP --- Co-Moderator of the Programmer Certification Forums
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic