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 are the default and parameterized constructors?

549


Is java good for beginners?

578


Explain about method local inner classes or local inner classes in java?

569


Is math an abstract class in java?

531


How do you classify Dialog Box?

647






Is {a, n, d} a palindrome? If you are given a random string, is it a palindrome or not?

617


What is unicode datatype?

521


Can we declare a class as static?

588


What do you know about the garbate collector?

598


Difference between arraylist and vector.

584


What about main thread in java?

644


What is core java called?

522


What is protected access modifier?

573


Can we execute java program without main method?

516


State the difference between strings and arrays.

597