aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
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
Author

EXAMCRAM CD Q:TEST 2, Q 11

ZEESHAN AZIZ
Ranch Hand

Joined: Jan 15, 2001
Posts: 162


QUESTION:
You have an application, which executes the following line.
Thread myT = new Thread();
myT.start();
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?
/Mike
William Brogden
Author and all-around good cowpoke
Rancher

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

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

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
Rancher

Joined: Mar 22, 2000
Posts: 12805
    
    5

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."
Bill

------------------
author of:
Annie Naqvi
Ranch Hand

Joined: May 04, 2001
Posts: 39
Hi,
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.
Regards,
Annie
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12805
    
    5
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.
Bill
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: EXAMCRAM CD Q:TEST 2, Q 11