• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help.....Questions from Mock Exam

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i havei have certain doubts regarding these questions from a mock exam the url is http://www.geocities.com/SiliconValley/Orchard/9362/java/q_a/index.html
Q [45] Which statements are true about listeners?
A. The return value from a listener is of boolean type. //false return type is void
B. Most components allow multiple listeners to be added. // true
C. A copy of the original event is passed into a listener method. //false copy of the reference is passed
D. If multiple listeners are added to a single component, they all must all be friends to each other. //false
E. If the multiple listeners are added to a single component, the order [in which listeners are called is guaranteed]. //false
My ans: is only B
The answer given is : 8 & C.
Q No[47]
<pre>
1. public void method(){
2.
3. if (someTestFails()){
4.
5. }
6.
7.}
</pre>
You want to make this method throw an IOException if, and only if, the method someTestFails() returns a value of true. Which changes achieve this?
A. Add at line 2: IOException e;
B. Add at line 4: throw e;
C. Add at line 4: throw new IOException();
D. Add at line 6: throw new IOException();
E. Modify the method declaration to indicate that an object of [type] Exception might be thrown.
My ans: C & E.
answer given : D & E.
Q No[60]
Consider the following code:
<pre>
1. public void method(String s){
2. String a,b;
3. a = new String("Hello");
4. b = new String("Goodbye");
5. System.out.println(a + b);
6. a = null;
7. a = b;
8. System.out.println(a + b);
9. }
</pre>
Where is it possible that the garbage collector will run the first time?
A. Just before line 5
B. Just before line 6
C. Just before line 7
D. Just before line 8
E. Never in this method
My ans: B
answer given: C
Regarding this question i thing the new string object created at line 5 i.(a+b) will be available for G.C after line 5 i.e before line as there are no references attached to this object.
Please correct me if I am wrong
Thanx in adv
Amit
 
Enthuware Software Support
Posts: 4828
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Your answer is correct. A copy of the reference of the original even is passed.
2. Your answer is correct.
3. Concept : Interned Strings ( ie. String literals, strings created with string literals and + operator and by calling intern() method on a string) are never garbage collected. So String returned by a + b will never be GCed.
So this means option C is correct.
There is 1 problem with this question though. It is not properly framed. GC can run ANY TIME. It's not like it will run only if something is available for collection. What this question is trying to ask ( probab. is ) after what earliest line is any object eligible for GC. ( This does not mean this is the earliest time the GC may run)
HTH,
Paul.
------------------
Get Certified, Guaranteed! http://pages.about.com/jqplus

[This message has been edited by Paul Anil (edited September 24, 2000).]
 
Amit Punjwani
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anil,
Thanx for the clarifications but. But I am not yet clear regarding the question on G.C U have said that String literals are never G.Ced. I agree totally with u. But in question 60 at
line 5 an object is being created by (a+b). Is this also a String literal? Or is it an object created on the heap memory?.
If it is a String literal then u're ans is right.
Still Confused...........
Amit

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I encounted all those three questions in my yesterday's exam, except:
Q[45]: there is no option C, and the option E with meaning of the order in which listeners are called is NOT guaranteed(//true)
and another option added.
Q No[47]: There is no option E, perhaps another option added.
Q No[60]: exactly same, I selected : Just before line 7

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is answer 'E' correct for 47? Just because an exception maybe thrown does not mean that it will definitely be thrown if and only if ifSomeTest() is true.
Can someone answer my question?
Thanks!
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Amit,
Yeah I agree with you, the (a + b) translates to
new StringBuffer().append(a).append(b).toString()
and this object should be eligible for G.C. once println() has returned, am I right?
Comments please!

Originally posted by Amit Punjwani:
Anil,
Thanx for the clarifications but. But I am not yet clear regarding the question on G.C U have said that String literals are never G.Ced. I agree totally with u. But in question 60 at
line 5 an object is being created by (a+b). Is this also a String literal? Or is it an object created on the heap memory?.
If it is a String literal then u're ans is right.
Still Confused...........
Amit


 
Ray Hsieh
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
The result of + operator, both operands of which are Strings can only be interned if both of them can be calculated at compile time (i.e.: this is interned)
String a = "aa" + "aa";
String b = "bb" + "bb";
but this is not!
String c = "ab" + new String("cd");
i.e.: the output of this program is BLAH and BLEH:
String uu = "ab" + "cd";
if(uu == "abcd") {
System.out.println("BLAH!");
} else {
System.out.println("BLEH!");
}
String uu1 = "ab";
String uu2 = "cd";
String uu3 = uu1 + uu2;
if(uu3 == "abcd") {
System.out.println("BLAH!");
} else {
System.out.println("BLEH!");
}
Comments please?

Originally posted by Paul Anil:
3. Concept : Interned Strings ( ie. String literals, strings created with string literals and + operator and by calling intern() method on a string) are never garbage collected. So String returned by a + b will never be GCed.
So this means option C is correct.
[/B]


 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please ask one question per post!!!

Ajith
reply
    Bookmark Topic Watch Topic
  • New Topic