0

I keep reading about serialization.. I understand how to serialize and deserialize custom objects. But I am not able to understand the rational behind why many classes in JAVA API implement Serialize by default.

SSB
79710 silver badges24 bronze badges
asked Feb 4, 2014 at 14:47
2
  • 2
    Why shouldn't they? Surely it makes sense for these classes to implement Serializable rather than having to write all the logic manually everytime you want to serialize an object? It doesn't force you to serialize them, it just makes it easy to if you need to. Commented Feb 4, 2014 at 14:53
  • 'So many' is meaningless. * Which* JDK classes implement Serializable that shouldn't, in your opinion? Commented Feb 4, 2014 at 17:38

3 Answers 3

3

Because there are cases which require the instances of these classes to be

answered Feb 4, 2014 at 14:50
Sign up to request clarification or add additional context in comments.

Comments

3

Because you can only serialize objects that are serializable. So if you have a field of a non serializable type, this field will not be serialized

answered Feb 4, 2014 at 14:50

4 Comments

Do you meant to say a class having HAS-A relationship with a String field scenario? Ex An Emp class implementing Serializable having a field EmpName as String.When Emp is Serialized,EmpName will be serialized only because String implements Serializable
yes! if an attribute type doesn't implement serializable, it cannot be serialized
In that case,Object class can implement Serializable so that all objects in both API and custom classes will be automatically eligible for Serialization ryt??
2

Because these classes are meant to be stored in some persistent storage or transferred via network as stream of bytes.

answered Feb 4, 2014 at 14:51

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.