I want to know the disadvantages of making a class serializable in java;
disadvantages in terms of memory allocation and accessibility.
any link on this topic will be helpful
Thanks in advance.
disadvantages in terms of memory allocation
Zero.
and accessibility
Zero. I don't understand the question but the answer is still zero.
If you don't want a specific class member to be serialized, you can always make it transient, which will save any serialization overhead connected with the class that contains that member.
The act of implements Serializable
itself has zero negative consequences.
I don't know what you mean by 'safe', but using Serialization for deep copies certainly works.
If you look at Java and its session objects, pure object serialization is used.
Assuming that an application session is fairly short-lived, meaning at most a few hours, object serialization is simple, well supported and built into the Java concept of a session.
However, when the data persistence is over a longer period of time, possibly days or weeks, and you have to worry about new releases of the application, serialization quickly becomes evil.
As any good Java developer knows, if you plan to serialize an object, even in a session, you need a real serialization ID (serialVersionUID), not just a 1L, and you need to implement the Serializable interface.
However, most developers do not know the real rules behind the Java deserialization process.
If your object has changed, more than just adding simple fields to the object, it is possible that Java cannot deserialize the object correctly even if the serialization ID has not changed.
Suddenly, you cannot retrieve your data any longer, which is inherently bad.
Please visit https://softwareengineering.stackexchange.com/questions/191269/java-serialization-advantages-and-disadvantages-use-or-avoid
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With