3] is it true that : a) if sleep() method is called on any thread in a synchronized method it does NOT relaese the lock on the object b)the access modifier of the default constructor is same as that of it's class. i believed it was public always. c) class fields with static modifier will not be serialised. d) if a runtime exception is thrown in finalize method it is simply ignored and the object is garbage collected. e) if an object is re_referenced in it's finalize method it is not garbage collected in that sweep but in the next sweep of G.C the finalize method will not be called and the object will be garbage collected.
hi shilpa.. let me try to give the answers to ur ques.. they are correct. .as far as i know.. 1. the sleep() method does NOT release the lock on an object.. 2. the access modifier of the default constructor(which the compiler provides in case none is given) is ALWAYS public. 3. there is nothing which says that class fields with static modifier will not be serialized.. i believe a field has to be transient to achieve the effect.. 4. i am not so sure abt this one.. 5. True hope this helps u..
a) if sleep() method is called on any thread in a synchronized method it does NOT release the lock on the object TRUE b)the access modifier of the default constructor is same as that of it's class. TRUE This is from JLS, 8.8.7 Default Constructor �...If the class is declared public, then the default constructor is implicitly given the access modifier public; if the class is declared protected, then the default constructor is implicitly given the access modifier protected; if the class is declared private, then the default constructor is implicitly given the access modifier private; otherwise, the default constructor has the default access implied by no access modifier. � c) class fields with static modifier will not be serialized. FALSE d) if a runtime exception is thrown in finalize method it is simply ignored and the object is garbage collected. TRUE This is from Bill Venners. Object Finalization and Cleanup �...You should also keep in mind that Java considers an object to be finalized whether the finalize() method returns normally or completes abruptly by throwing an exception. Garbage collectors ignore any exceptions thrown by finalizers and in no way notify the rest of the application that an exception was thrown.� e) if an object is re-referenced in it's finalize method it is not garbage collected in that sweep but in the next sweep of G.C the finalize method will not be called and the object will be garbage collected. TRUE the finalize() method will be invoked of an object only once. If an object object was re-referenced in it's finalize method and later becomes available for garbage collection, the finalize() method will not be invoked again. See the link above. [This message has been edited by Mapraputa Is (edited February 25, 2001).]
I think Static variables are not serialised. Actually serialisation is done on the objects and static variable does't belong to Object, they belong to the class. So they are not serialised. Khalid Mughal book also says so( see page 588). Rakesh Sharma
Clarification regarding static variables I based my answer on Java Developer�s Journal article �secrets of Java Serialization�. They said �for static variables that are initialized when declared, serialization doesn�t present any special problems�. I understood it in the sense that static vars ARE serialized, but reality is more complicated. I did not find any explicit statement that static vars ARE NOT serialized. But description for java.io.Serializable Interface said: �...The readObject method is responsible for reading from the stream and restoring the classes fields. It may call in.defaultReadObject to invoke the default mechanism for restoring the object's non-static and non-transient fields. � url: http://java.sun.com/products/jdk/1.2/docs/api/java/io/Serializable.html I think it means that static vars will not be written into the stream � in this sense they are not serialized. However, when the object�s state is read, static variables are set in their initialized values (which are read, this is my guess, from class code). It means, if you changed value for static variable and then serialized your object, new value will be lost. You have to change writeObject() method of the class to transmit a new value. To add some useful information: if your class has 1) inner classes; 2) variables referring to them; you have to declare inner classes serialized also, otherwise you get NotSerializableException. (I do not think it is in exam objectives He, looks like to answer questions is more useful for me, than for those, who asked... (I am laughing at myself)