This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes I neeed answers for these Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "I neeed answers for these" Watch "I neeed answers for these" New topic
Author

I neeed answers for these

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Multithreading may be correctly accomplished in Java in which of the following ways?

a)Extend the Thread class, provide an implementation for the start method and create an instance of this new subclass
b)Create a class which implements the Threadable interface, and pass an instance of this class to a Thread Class constructor
c)All of the above
d)None of the above

Locking is the main mechanism for restricting simultaneous thread access to specific java code. Which of the following statement(s) are true regarding locks / monitors?
a)One lock / monitor is associated with each Class
b)One lock / monitor is associated with each Synchronized block
c)One lock / monitor is associated with each Thread
d)One lock / monitor is associated with each Object
e)All of the above
With respect to User and Daemon threads:
a)Daemon threads can not be destroyed
b)Running User threads prevent a Java VM from exiting
c)Running Daemon threads prevent a Java VM from exiting
d)Daemon threads can not be grouped together
e)The Java VM will exit when no non-daemon threads are running
Roll
Ranch Hand

Joined: Jan 20, 2000
Posts: 52
I think
Answer for Q)1 is b)
for Q)2 is b
for 3) is a) b)
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20495
    ∞

Q1) d - there is no "Threadable interface". There is a Thread class and a Runnable interface. And you don't implement the start() method, you implement the run() method.
Q2) a, b and d
Q3) c

permaculture Wood Burning Stoves 2.0 - 4-DVD set
Sunita
Greenhorn

Joined: Jun 08, 2000
Posts: 28
Hi
This message was posted here long back.Today I had gone through this.
1.With respect to User and Daemon threads:
a)Daemon threads can not be destroyed
b)Running User threads prevent a Java VM from exiting
c)Running Daemon threads prevent a Java VM from exiting
d)Daemon threads can not be grouped together
e)The Java VM will exit when no non-daemon threads are running .
Answer given by paul is c.But I think the answer for this is b.
2.Locking is the main mechanism for restricting simultaneous thread access to specific java code. Which of the following
statement(s) are true regarding locks / monitors?
a)One lock / monitor is associated with each Class
b)One lock / monitor is associated with each Synchronized block
c)One lock / monitor is associated with each Thread
d)One lock / monitor is associated with each Object
e)All of the above
For this paul has given the answers as a, b and d.
But I had read somewhere that the lock is only associated with synchronized block.
Can anyone throw somelight on this to help me with explanation.
Thanks and regards
Sunita
UPENDRA KANE
Greenhorn

Joined: Sep 29, 2000
Posts: 24
I think,
1.When Last of the Non-Deamon thread stops, JVM exits. hence, ans is B.
2. There is lockk available for Synchronized Block, an object & a class. So a,b d is correct.


Regular
Puneet Piplani
Greenhorn

Joined: Sep 29, 2000
Posts: 4
2. I think the that lock is only associated to object and class.In synchronize block also u have to specify an object whose lock will be obtained before executing the block.
So answer should be only object and class.
Arthy
Greenhorn

Joined: Sep 22, 2000
Posts: 9
I think
Ans for 1st question is d (i.e none of the above)
Ans for 2nd question is d (i.e. lock is associated with each object not even class).
Ans for 3rd question is b
mohit joshi
Ranch Hand

Joined: Sep 23, 2000
Posts: 243

I agree with Puneet. Locks/Moniters are associated with only
Objects and Classes.
If a class has many Synchronized methods, it doesnt mean that is has many locks. There is only one lock associated with the object. so when one synchronized method is executing, another synchronized method cannot be executed.
Swati Gupta
Ranch Hand

Joined: May 28, 2002
Posts: 106
It's a very old post. But today I came across this.
My answer is 1.d
2.d lock associated with object
3.b Runnnind User thread prevennts JVM to exit.
Am I write?
geetha nagarajan
Ranch Hand

Joined: Jul 13, 2001
Posts: 94
I think the answers are:
1.D
2.B,C,D
3.B,E
Are they correct ?
[ May 31, 2002: Message edited by: geetha nagarajan ]
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
1) D
2) It depends on what "lock association means".
In Java we could use the lock of any object to syncronize a method or block. Because classes and threads in the JVM are objects it is possible to use their locks also.
You can consider, as well, the lock of an object associated with the method or block is guarding.
The answers, thus, vary due to the meaning of the association term you chose. Not a good question for the exam I'm afraid.
3) B unles one of them executes System.exit(0)


SCJP2. Please Indent your code using UBB Code
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by Shan:
Multithreading may be correctly accomplished in Java in which of the following ways?
a)Extend the Thread class, provide an implementation for the start method and create an instance of this new subclass
b)Create a class which implements the Threadable interface, and pass an instance of this class to a Thread Class constructor
c)All of the above
d)None of the above

The answer is D. You don't override start, you override run and there is no Threadable interface. Rather, you could implement the Runnable interface.
Originally posted by Shan:

Locking is the main mechanism for restricting simultaneous thread access to specific java code. Which of the following statement(s) are true regarding locks / monitors?
a)One lock / monitor is associated with each Class
b)One lock / monitor is associated with each Synchronized block
c)One lock / monitor is associated with each Thread
d)One lock / monitor is associated with each Object
e)All of the above

This one's rather fuzzy. A and D are obviously correct. However, I believe that you could have more than one lock associated with a thread or a synchronized block. For example, let's say that a thread calls a synchronized method on an object. That thread will then obtain that object's lock. Now, suppose that, inside that method, a synchronized method is invoked on another object. The thread also gains the lock for that object. The thread has now acquired two locks. You can create a similar example for a synchronized block. Therefore, the answer should be A & D.
However, I came to this solution by making an assumption about how the exam uses the word "Thread." If the exam intended a Thread to be the Java class Thread or an instance of that class, then, just like answers A & D, there would be one lock associated with a Thread. That's where the question becomes fuzzy.
I would say that the answer should be A & D.
Originally posted by Shan:

With respect to User and Daemon threads:
a)Daemon threads can not be destroyed
b)Running User threads prevent a Java VM from exiting
c)Running Daemon threads prevent a Java VM from exiting
d)Daemon threads can not be grouped together
e)The Java VM will exit when no non-daemon threads are running

The answer is B. You could have multiple non-daemon threads that aren't running but are "alive." Until all of these threads are terminated, the JVM will continue to run.
I hope that helps,
Corey
[ May 31, 2002: Message edited by: Corey McGlone ]

SCJP Tipline, etc.
Swati Gupta
Ranch Hand

Joined: May 28, 2002
Posts: 106
Thanks Jose and Corey
Shiva Mantri
Greenhorn

Joined: Dec 30, 2002
Posts: 19
Originally posted by Shan:
With respect to User and Daemon threads:
a)Daemon threads can not be destroyed
b)Running User threads prevent a Java VM from exiting
c)Running Daemon threads prevent a Java VM from exiting
d)Daemon threads can not be grouped together
e)The Java VM will exit when no non-daemon threads are running

In option b, Running User threads could call System.exit() and terminate the program and JVM. So, I think the answer should be 'e', according to JLS 12.8.
I am wondering about option a: deamon threads can not be destroyed. They can not be???
JLS 12.8 Program Exit
A program terminates all its activity and exits when one of two things happens:
* All the threads that are not daemon threads terminate.
* Some thread invokes the exit method of class Runtime or class System and the exit operation is not forbidden by the security manager.

-Shiva
ps: was reviewing all the old posts regarding threads to test my threads basics
Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
Do we have to know the details about hat a User Thread is and what a Daemon thread is? i didn't know we had to, the book i am studying has mentioned nothing about User or Daemon in this context.


giddee up
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
nally posted by Jasper Vader:
Do we have to know the details about hat a User Thread is and what a Daemon thread is? i didn't know we had to, the book i am studying has mentioned nothing about User or Daemon in this context.
I think everything you need to know about daemon and user threads is on this page already : )
So, you should understand the basic idea and pay atttention to what Corey wrote and you'll have everything you need.
Cheers,
Kathy
"To be remembered, it must be memorable."
[so when you're studying, find a way to make this stuff interesting, exciting, strange, shocking, ANYTHING that makes your brain wake up and pay attention.]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: I neeed answers for these
 
Similar Threads
daemon
daemon threads
IBM Sample Question
Thread Help!!!
Locks