• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Doubt about join() and yield(); Source: OUKC mock exam.

 
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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.

 
Ranch Hand
Posts: 75
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think F is correct.

Yield give priority to main thread as it says.
This way, the new thread tends to print later, so much "2" will appear at the end since "1" will be printed first.
Then, main thread will join the new thread finnishing its task, so that printing remaining "2"s.

I hope this help!

Edit: though, this behaviour is NOT guaranteed!
 
author
Posts: 9046
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can you tell us what "OUKC" stands for?

thanks,

Bert
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



To be fair, I have never heard of the source (or the acronym) either.
 
Bert Bates
author
Posts: 9046
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ikpefua,

Thanks for the info! I always just thought of "Oracle", this OUKC is good to know.

Bert
 
Ranch Hand
Posts: 173
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

I am still not clear about choosing option F instead of E,
Can some one help me about it??
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.


 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to CodeRanch, Ivan Rivero Alonso
 
Hareendra Reddy
Ranch Hand
Posts: 173
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ??
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.









 
Hareendra Reddy
Ranch Hand
Posts: 173
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !!
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!.

 
Hareendra Reddy
Ranch Hand
Posts: 173
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you jackzia ...

So is that question is really asking the output relative to the output when line 5 was removed??

Nice to know that you can speak 5 languages including spanish and english,now you can visit almost any part of the world

I think practicing more questions alone doesn't make me all right ,i should read carefully each question...
 
Bert Bates
author
Posts: 9046
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First off I must say with all sincerity that I am always very impressed by candidates for whom English is not their first language! wow!

With that said, one perspective about question wording that might be useful is this:

You might want to imagine that these exam questions are like micro software specs. As a Java developer, a part of your job is to read and properly understand the specifications that you receive. If you're having difficulty understanding the precise meanings of mock exam questions, then that should be an important part of your study plan, because that skill will be necessary on the job.

In other words, when you're on the job, it doesn't matter how awesome your code is, if it doesn't meet the spec.

hth,

Bert
 
Hareendra Reddy
Ranch Hand
Posts: 173
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much Bert ...
 
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic