What is the need to implement Serializable interface (with
no methods) for objects which are to be serialized ?
We can write our own functionality which writes objects to
streams then why we need to implement and tell JVM that
which objects can be serialized.

Answer Posted / akj504

Ya that answers are expected but...
If we open ObjectOutputStream.java (which is used for
serialization) then we see the following code :

............................
writeObject0(Object obj, boolean unshared){
.............
} else if (cl.isArray()) {
writeArray(obj, desc, unshared);
} else if (obj instanceof Serializable) {
writeOrdinaryObject(obj, desc, unshared);
} else {
throw new NotSerializableException(cl.getName());
}
................

If we remove the checking instanceof (& recompile) or if we
override the writeObject0 method then
Will it still check whethere the class has implemented
serilizable ?

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is map in java?

736


What is identifier with example?

799


Difference between stack and queue?

801


What are the different types of collections in java?

737


If a class is declared without any access modifiers, where may the class be accessed in java programming?

897


What is javac in java?

762


What is methods in java?

768


Explain the importance of join() method in thread class?

849


Define immutable object?

843


What is final keyword?

874


What is meant by object?

789


What is qualitative variable?

733


What is the difference between size and length in java?

737


Howto get an object that will perform date & time calculations then format it for output in some different locales with different date style.can ne1 tel me the answer of this question.pls

1676


Differentiate between stringbuffer and stringbuilder in java.

757