• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Please help me

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am preapring for the java certification exam and have few doubts about the questions appeared in khalid's and deepak's mock exams, please help me
KHALID
------
1. which statements concerning the methods notify and notifyAll are true?
A. Instances of class Thread have a method called notify
B. A call to the method notify will wake the thread that currently owns the monitor of the object
C. The method notify is synchronized
D. The method notifyAll is defined in class Thread
C. When there is more than one thread waiting to obtain the monitor of an object, there no way to be sure which thread will be notified by the notify() method.
2. Under which circumstances will a thread stop
A. the method waitforId() in class mediaTracker is called
B. the run() method that the thread is executing ends
C. The call to the start() method of the Thread object returns
D. The suspend() method is called on the Thread object
E. The wait method is called on the Thread object
3.which is the earliest line in the following code after which the object created line marked (0)will be a candidate for being garbage collected, assuming no compiler
optimizations are done?
public class Q276a9{
static String f(){
String a="hello";
String b="byte";//(0)
String c=b+"!";//(1)
String d=b;
b=a;//(2)
d=a;//(3)
return c;//(4)
}
public static void main(String args[]){
String msg=f();
System.out.println(msg);//(5)
}
}
A. the line marked (1)
B. the line marked (2)
C. the line marked (3)
D .the line marked (4)
E. the line marked (5)

DEEPAK.HTMLPLANET.COM
---------------------
4.Consider the following class hierarchy and code fragments:
java.lang.Exception
|
java.io.IOException
/ \java.io.StreamcorruptedException java.net.MalformedURLException

try {
URL u = new URL(s); // assume s is defined String
Object o = in.readObject( ); // in is a valid
System.out.println("Success");
}
catch(MalformedURLException e) {
System.out.println("Bad URL");
}
catch( StreamCorruptedException e ) {
System.out.println("Bad file contents");
}
catch(Exception e) {
System.out.println("General Exception");
}
finally {
System.out.println("doing finally part");
}
System.out.println("carrying on");

What lines are output if the method at line 2 throws a MalformedURLException ?
The Answers:
Bad URL
doing finally part
carrying on
My Doubt is about the answer-carrying on, does the program does not terminate after finally.why and when does code after finally is not executed


5 Method names can be re-used anywhere, as long as certain conditions are met:
A. in sub-class with identical arguments and identical return type
B. In same class or sub-class but with same arguments
C. In unrelated classes
D. In same class or sub-class but with different arguments
The Answer: A,C,D,E
Doubt is about the answer- C, whether it is right.
6. What are overloaded methods ?
A. With same argument list and return type
B. with different argument list and same return type
C. overloaded methods can be in different classes
D. Methods with the same name
C. with different arguments list and return type
The Answer is B,C,D,E,F
Doubt is about answer -C, whether it is right.
7.Which of the following are feautres of object oriented language
A. Late binding
B. Overloading
C. Overriding
The answer: A,C
Doubt is whether B is not a feautre OOL
I will be pleased if anyone can help me
Thanks
George
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi George
Comments on Q4
The code in finally always prints as we know..So in case of an error which is not caught be the program even in that case finaly is printed but in that case the program doesn't continue and it exits out.
This my explaination of your concern, if anybody else finds it to be incorrect please post.
Thanks
Nasir
 
Ahmed Nasir
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Comments on Q5
I think C is definiteley a true statement as it really won't matter in unrelated classes to have any method names.
What do you think folks!!.
Nasir
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q2;
Under all conditions the thread will stop. The word stop is too
harsh here. IF it means terminate then only b,c are correct.
Q1:
A. Instances of class Thread have a method called notify
//FALSE, only the class Object has the method notify().
B. A call to the method notify will wake the thread that currently owns the monitor of the object
//FALSE, it will wake up waiting threads on that object.
C. The method notify is synchronized //TRUE
D. The method notifyAll is defined in class Thread
//FALSE , Only Object class has this method.
E. When there is more than one thread waiting to obtain the monitor of an object, there no way to be sure which thread will be notified by the notify() method.
//TRUE.

Q3:
Strcitly speaking the object defined on line 0 will not be garbage collected since they are in the string pool.
Hope this helps.
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
2. Under which circumstances will a thread stop
A. the method waitforId() in class mediaTracker is called
B. the run() method that the thread is executing ends
C. The call to the start() method of the Thread object returns
D. The suspend() method is called on the Thread object
E. The wait method is called on the Thread object
My understanding
A) I tried to track down the waitForId() method, which calls some other methods, which call some method of the toolkit class,
which are supposed to load the image. So untill the Image is loded the thread waits. If the thread is waiting, then it is not running so it has stopped (running).True.
B)The run method execution ends. The thread stops executing because there is nothing to execute, so it stops ( running).True.
C) The start() method doesnt wait for the run method of the new thread to finish execution. start() method returns even if the thread of execution started by it is still executing.False.
D)Suspend Method is called on the new Object.(Do we need to know this for the exam?).By definition suspend Method will stop the thread untill it is resumed. True.
E)Wait method will also stop the thread from running, Untill it is notified by some other thread.True
My choices are not accepted by the Mughal Test.
I am sure this question has been discussed before, but I still havent come across a definitive answer. Kindly tell me link to some previous discussion of this question.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
george_tk,
Welcome to JavaRanch!
As you are new, please register with a proper name. PROPER NAMES ARE NOW REQUIRED!! Read this post for details.
Also, Please post one question per thead. It will keep the discussions focussed and uncluttered.
Thanks!
Ajith

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic