What would be the most likely impact to the output if line 5 was removed?
A. There would be no impact to the output.
B. Compilation would fail if line 5 was removed.
C. An exception would be thrown if line 5 was removed.
D. The total number of characters output might change.
E. The character "2" would appear more frequently near the end of the output.
F. The character "2" would appear less frequently near the end of the output.
Option F is correct. As the code stands the yield() will tend to give priority to the main thread, which will tend to place more "2" characters near the end of the output.
I chose E. because I thought that the yield() method "TENDS" to prevent line 6 from executing by giving "PRIORITY" to the main Thread which will place more "1" characters near the end of the output!
Another thing I am "SKEPTICAL" about is that line 11's behaviour is "GUARANTEED" to run by asking the "MAIN THREAD" to "PAUSE" for "THREAD t " to finish executing. Can someone please clerify my doubts?? Thank you for your help.
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
E. The character "2" would appear more frequently near the end of the output.
As the code stands the yield() will tend to give priority to the main thread, which will tend to place more "2" characters near the end of the output.
OK, so that other guy knows Java better than I do, but I bet he can't speak Wuhanese(a Chinese Dialect) like me.
Leon Omk wrote:Did you mistyped option E & F ? I think E is the correct answer.
E. The character "2" would appear more frequently near the end of the output.
As the code stands the yield() will tend to give priority to the main thread, which will tend to place more "2" characters near the end of the output.
No Leon, I did NOT mistype, the fact is that I even copied and pasted it to avoid errors!...I thought the same as you that option E is the correct answer but OUKC says it is option F with the above explanation, so I am confused...Can somebody help to clarify this?? Thanks.
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Bert Bates wrote:Hi,
Can you tell us what "OUKC" stands for?
thanks,
Bert
Hello Bert I appreciate your effort to fight against the possible use of stolen questions, however I am SURPRISED that OUKC is strange to you or anybody in this blog because of its popularity , I guess the same question should be asked about K&B ??(Joking)...Having said that, OUKC stands for: Oracle University Knowledge Center, I am a LEGALLY registered member thanks.
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Ikpefua Jacob-Obinyan wrote:Hello Bert I appreciate your effort to fight against the possible use of stolen questions, however I am SURPRISED that OUKC is strange to you or anybody in this blog because of its popularity , I guess the same question should be asked about K&B ??(Joking)...Having said that, OUKC stands for: Oracle University Knowledge Center, I am a LEGALLY registered member thanks.
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Hareendra Reddy wrote:Hello all,
I am still not clear about choosing option F instead of E,
Can some one help me about it??
Hello Hareendra, the fact is that this question gave me a tough time before I got to understand it.
Now lets us analyse this program with the basic information that we have learnt about threads, I hope it helps:
1. This program has TWO threads; the main thread (also known as the main method) AND thread created in line 9 referenced by (t).
2. In line 10, the main thread loads several ("1") in static String s.
3. In line 6, thread (t) loads several ("2") in static String s.
4. In line 5, The yield() method gives PRIORITY to the main thread, (REMEMBER that the main thread loads several "1")
5. The output prints out several "1" and later prints several "2" at the end
In line 11, You Might be confused about the join() method (Which says to the main thread: "pause for t to finish executing"), YES this is true!!
But TAKE NOTE, Each time Thread t gets to line 5, The yield() says: "STOP!! HERE, give way to the main thread", meaning line 6 is does not execute TEMPORARILY.
This makes several "1" to be loaded FIRST and later several "2".
Back to the question, What would be the most likely impact to the output if line 5 was removed???
The removal of line 5 simply means we NO LONGER have the yield() method, AND which means NO thread has a PRIORITY, AND which means "1" and "2" are LIKELY to be loaded to static String s AT RANDOM, AND which means that the output will RANDOMLY display "1" AND "2". like this:
With the yield() method = NO RANDOM DISPLAY = 1111111111111111111112222222222 = more "2"
Without the yield() method = RANDOM DISPLAY = 111221122211221112211 = less "2"
___________________________________________________________________________________________________________
What would be the most likely impact to the output if line 5 was removed???...(Wituout the yield())
Answer F. The character "2" would appear less frequently near the end of the output. CORRECT!
VERY IMPORTANT: THE FUNCTION OF THE yield() METHOD IS NOT GUARRANTEED.
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Hareendra Reddy wrote:Thank you jackzia .. i didn't notice the actual question "What would be the most likely impact to the output if line 5 was removed? "
Still i think the question is ambiguous , now both the threads are almost identical and do the same operation , then how it is going to print less 2's ...
I mean in what way does it most likely print less 2's at end ??
Harrendra how are you today?? I guess fine... The question is NOT 'AMBIGUOUS' it is 'TRICKISH' and let me warn you before hand I have written the exams twice, and with my PERSONAL experience in the exams 'TRICKISH' questions are there!! and they will DETERMINE your success. I advise you to get used to 'TRICKISH' questions by practicing mock exams. Let me take you back to line 5 of the program:
The yield() method in line 5 TEMPORARILY prevents line 6 from executing. It says "Wait for line 10 to execute FIRST"
My question to you is if the yield() method in line 5 is removed, dont you see that line 6 will execute and print out "2" in the SAME RATIO as line 10??
This is because The main thread() and the other thread (t) have the SAME PRIORITY!.
SAME PRIORITY 'LIKELY' output = 11122211122211212121212 = LESS "2" At the End!
Now if the yield() method in line 5 is NOT removed, then PRIORITY IS GIVEN TO MAIN THREAD to execute First!.
PRIORITY TO MAIN THREAD 'LIKELY' output = 11111111111111111112222222 = MORE "2" At the end!.
TAKE NOTE This program has 2 GUARRANTEES:
1. The join() METHOD is GUARRANTEED to funtion (That is telling main to wait for t).
2. Both threads will START and run to COMPLETION.
3. NOTHING ELSE IS GUARRANTEED THAT IS WHY I SAID 'LIKELY' output.
I hope you understand the above, If you STILL dont get it, then I advise you to go and study threads VERY HARD.
Thank you.
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Hareendra Reddy wrote:hi jackzia ,
I think my concepts about threads are clear...
Is that question asking the frequency of 2's relative to the output when line 5 is not removed ??
if this is the case i am really having hard time in understanding the english in questions ,
Do you remember my previous post about using words can, may etc !!![]()
@Hareendra yeah its true I remember!
....But dont worry keep practicing with lots and lots of mock exams and you will get better.
Anecdote: I speak 5 languages, as you can see, I live in Madrid Spain (I am not a native), I had to write my drivers lincence exams in Spanish language, I had similar problems, and the solution was intense practice with mock exams to make me get use to the 'CHARACTERISTICS' of the questions, and at the SECOND attempt I passed, so keep it up!.![]()
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |