This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Which of the following are printed to standard output?
a) 0 b) 1 c) 2 d) 3 e) Nothing and an exception is thrown
They say answer is b and c . I feel its 0 and 1. Is variable m incremented before or after comparison since its postfix i felt its after.. Please clear this..
For what reasons might a thread stop execution?
a) A thread with higher priority began execution. b) The thread's wait() method was invoked. c) The thread invoked its yield() method. d) The thread's pause() method was invoked. e) The thread's sleep() method was invoked.
Answer given is a,b,c,e.
I feel its a,b,e..Does yield method stop the execution .I read in some site it only stops execution if higher priority thread is present else it might start running again.. Whats the exact concept here..
Third snapshot: What line of code would begin execution of a thread named myThread?
was marked wrong since i didnt put semicolon.
Should we always put semicolon even if it is fill in blanks....
Hi, For the first question.....m is incremented after the comparison. let us go through the code. 1.m=0 which is less than 2.then m is incremented. so 1 is printed. 2.now,m=1 which is again less than 2 .then m is incremented. so 2 is printed. 3.now m=2 and condition is not satisfied.so the loop ends here.however m gets incremented. Regarding yield method,you are right. if there are no higher priority threads or threads of same priority in the runnable state,the same thread gets executed. hope this helps... vinu.
Hope ur first doubt is cleared with Vinu's explanation.
Reg 2nd snapshot :
Read the question carefully.It asks "For what reasons might a thread stop execution?".When yield method is invoked if at all higher priority thread exists than the current one then JVM scheduler may choose this higher priority thread for execution and stop(in other words pause) the execution of the current thread.Hope this is clear.
Reg 3rd snapshot :
Again question should be read carefully.They're asking for a line of code.So exact syntax would be expected!!.
Joined: Aug 02, 2005
Thanks for the response.. My queries are cleared...