Let me put it in this way:
What does JVM understands when it see a class implementing Serializable
What could be the code written to handle this? (If class is Serializable)
Let me put it in this way:
What does JVM understands when it see a class implementing Serializable
What could be the code written to handle this? (If class is Serializable)
Many classes cannot be serialized.
How can you serialize a UI element or a network socket or a thread?
You don't need to serialize (or) save state of every object. It doesn't make sense. Another reason could be instead of saying, by default, authors might thought let programmer decide. Here is interesting discussion on this from java team.
The decision to require that classes implement the java.io.Serializable interface was not made lightly. The design called for a balance between the needs of developers and the needs of the system to be able to provide a predictable and safe mechanism. The most difficult design constraint to satisify was the safety and security of Java classes.
If classes were to be marked as being serializable, the design team worried that a developer, either out of forgetfulness, laziness, or ignorance might not declare a class as being Serializable and then make that class useless for RMI or for purposes of persistence. We worried that the requirement would place on a developer the burden of knowing how a class was to be used by others in the future, an essentially unknown condition. Indeed, our preliminary design, as reflected in the alpha API, concluded that the default case for a class ought to be that the objects in the class be serializable. We later changed our design only after security and correctness considerations convinced us that the default had to be that an object not be serialized.
There are a lot of examples of class which cannot be Serialized, not just those in the GUI.
From java.lang
ClassLoader, Compiler, Math, Package, Process, Runtime, Shutdown, StrictMath, System, Thread, ThreadGroup, ThreadLocal, Void