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.
What are the possible results of attempting to compile and run the program? a. Prints a number that is less than 1000. b. Prints a number between 1000 and 9999. c. The printed number must always be greater than 10000. d. Compiler error. e. Run time error. f. None of the above
I selected f. The answer given is c. Though the chances are that c may be the correct answer but isn't it possible that exactly 10000 is printed. [ May 17, 2003: Message edited by: Anupam Sinha ]
Joined: Apr 13, 2003
Well at the time of writing the first post I hadn't tried out the code. Now I tried it and it infact gives 10000 as the output. I guess that it may vary from computer to computer and even vary when run different times on the same computer. [ May 17, 2003: Message edited by: Anupam Sinha ]
Yes, I should have said that the number will be greater than or equal to 10000. The purpose of the question was really to point out that the InterruptedException is not thrown when the interrupt method is invoked on a thread that is not sleeping or waiting or blocking in the not-runnable state for any other reason. I should probably mention that the real exam does not place a lot of emphasis on the interrupt method or the yield method. I try to avoid the use of the yield method but I used it in this question because the sleep method could cause the InterruptedException to be thrown. Here's another interesting point. We all assume that the sleep method causes a thread to sleep for a period of time that is at least as great as the time specified by the argument. However, in reality, the actual behavior of the sleep method--at least on a Windows system--is a little different. Instead--on Windows--the actual sleep period can be shorter than the time specified by the argument. Has anyone seen this behavior documented anywhere? Does Sun acknowledge it?
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Joined: Apr 13, 2003
I tried this out.
Well more often than not slept for less time. Few reasons why it may happen so 1. Your and my computer is very very fast, defies time. 2. Sun Microsystems time's and Microsoft time's are not fully compatible with each other. 3. Java is ahead of its time. 4. Its time for us to buy new computer. Hope that helps. That Should [ May 17, 2003: Message edited by: Anupam Sinha ]