Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

vinay singh

+ Follow
since Nov 24, 2000
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by vinay singh

I made it with 66% in my first attempt. I do not have any prior programming experience. Java is the first programming language I learned. The real exams questions were really difficult. But JQPlus exam really helped me a lot. Also, Marcus Green Tutorial was helpful for the last minute.
I would like to thanks everyone in Javaranch for providing me constant support.
21 years ago
Another question taken from JQuest mock exam.
1. public synchronized void someMethod() {
2. //lots of code
3. try {
4. Thread.sleep(500);
5. } catch(InterruptedException e) {
6. //do some things here.
7. }
8. //more and more code here
9. }
Select all correct answers
a. The code causes compilation error - sleep cannot be called inside synchronized methods.
b. The thread sleeps for atleast 500 milliseconds in this method if not interrupted.
c. When the thread "goes to sleep" it releases the lock on the object.
d. The "sleeping" threads always have the lock on the object.
The correct answers are c and d.
But aren't they contradictory???
Can anyone explain.
This is a question taken from JQuest mock exam.
Here is part of the code for a class which implements the Runnable interface.
1. public class Whiffler extends Object implements Runnable {
2. Thread myT ;
3. public void start(){
4. myT = new Thread( this );
5. }
6. public void run(){
7. while( true ){
8. doStuff();
9. }
10. System.out.println("Exiting run");
11. }
12. // more class code
Assume that the rest of the class defines doStuff, etc and that the class compiles without error. Also assume that a Java application creates a Whiffler object and calls the Whiffler start method, that no other direct calls to Whiffler methods are made an that the Thread in this object is the only one the application creates. Which of the following are correct statements ?
a. The doStuff method will be called repeatedly.
b. The doStuff method will never be executed.
c. The doStuff method will execute atleast one time.
d. The statement in line 10 will never be reached.
According to me 'a' is the right answer. But the correct answers are 'b' and 'd'.
Can anybody explain me why 'b' and 'd' are the correct answers.
Can any one tell me if the following has been deprecated in Java 2
1) public static void sleep (long milliseconds) throws InterruptedException
2) public static void sleep (long milliseconds, int nanoseconds) throws InterruptedException