This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes EXAMCRAM CD Q:TEST 2, Q 11 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 "EXAMCRAM CD Q:TEST 2, Q 11" Watch "EXAMCRAM CD Q:TEST 2, Q 11" New topic


Ranch Hand

Joined: Jan 15, 2001
Posts: 162

You have an application, which executes the following line.
Thread myT = new Thread();
Sellect all answers:
a: Thread myT is now in a runnable state.
b: Thread myT has NORM_PRIORITY
C: Thread will die without accomplishing anything.
d. run method in class where statement occurs will be executed.
According to tester, answers are a, c.
However I think it is not correct. I think when new instance of Thread is created, it will be in ready state, which makes choice one wrong.
I think newly created thread instance will have normal priority attached to it, which make 2 a right choic, in my consideration.
I think c is not right, while d is correct.
I would like to confirm my assumptions.
Mikael Jonasson
Ranch Hand

Joined: May 16, 2001
Posts: 158
b might be correct. However, new threads are created with the same priority as the current thread, so if we've changed priority before the above statments, it will not have NORM_PRIORITY.
d on the other hand is not correct. Since you are creating an instance of Thread, not the class you're in, Thread's run()-method (which does nothing, so c is correct) will be executed.
Does this explain it?
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13001
You know, I put my email address in that book for a reason - so readers could ask me questions like this.
Mikael's answer is correct.
Rashmi Hosalli
Ranch Hand

Joined: Jun 25, 2001
Posts: 50
So,is 'b' the right answer too or is it only 'c'?
akila raman

Joined: Jun 26, 2001
Posts: 8
The start() method puts the thread in the ready to run state. So
option a is not valid.Given the following lines of code we are not changing the priority of thread so it has NORM_PRIORITY and option b is valid and option c is valid too and d is not correct.
- akila
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13001

b: Thread myT has NORM_PRIORITY -- WRONG
A new Thread gets the priority of the Thread that created it as Mikael already said.
a. Thread myT is now in a runnable state. -- TRUE
My copy of Java Threads says "A thread is in the runnable state once its start method has been called."

author of:
Annie Naqvi
Ranch Hand

Joined: May 04, 2001
Posts: 39
Sorry Bill I do not get your point... as I read in Simon Robert's guide that when start() method is called it makes the thread "eligible to run" and that the thread is still contend for CPU time.Thus it is in the "ready" state and not in "runnable" state.
And that's what I know.
Your comments required Bill.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13001
What do you think the difference between what you are calling the ready state and what I am calling the runnable state is?
I don't see any difference. If a Thread is runnable, it may be scheduled for running time by the JVM at any time.
I agree. Here's the link:
subject: EXAMCRAM CD Q:TEST 2, Q 11
It's not a secret anymore!