HomePage     |    Contact Us    |   Contribute     |  Forums     |  Blog

 
 
Java J2EE Interview Questions

 

12. What is the difference between optimistic lock and pessimistic lock?

Optimistic lock is an implicit lock that tries to make best assumption about locking strategy and minimize time spent in lock of resource. Optimistic lock is usually implemented with some kind of timestamp strategy. Pessimistic lock is an explicit lock that set by client.

13.  Is null a reserved word in Java? Can you declare a variable with a name of null?

Yes, null is a reserved word in Java, we cannot declare null as a variable name.

14.  What is the word transient?

Transient means that the value of this member variable does not have to be serialized with the object.

15.  When do you need explicit casting of objects?

If we assign a superclass to a variable of subclass data type then we need to cast that object.

16.  What is the method sleep()? How is it different from wait()?

The code

sleep(1000);

puts thread aside for exactly one second. The code

wait(1000);

causes a wait of up to one second.  A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.

.