aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes one more question from Dan's questions 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 "one more question from Dan Watch "one more question from Dan New topic
Author

one more question from Dan's questions

Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Here is the question url: Dan's questions on threads
Question 17

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 ]
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
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 ]
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
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>
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: one more question from Dan's questions