The document discusses serialization in Java. Serialization is the process of converting a Java object into a byte stream to transfer the object between Java Virtual Machines. To serialize an object, its class must implement the Serializable or Externalizable interface. There are advantages like simplicity and universal applicability, but also disadvantages like objects becoming brittle during deserialization. Best practices for serialization include using javadoc tags and avoiding serializing certain fields.
5. www.edureka.co
Serialization in Java is the process of converting the Java code
Object into a Byte Stream, to transfer the Object Code from one
Java Virtual machine to another and recreate it using the process
of Deserialization.
9. www.edureka.co
To Serialize an object, the parent class should implement
either of the following interfaces:
• java.io.Serializable
• java.io.Externalizable
HOW DO WE SERIALIZE AN OBJECT?
11. ADVANTAGES
• Serialization process does not require third-party
software.
• The Serialization procedure is simple .
• Serialization procedure is universal .
• It is easy to use and simple to customize.
• Serialized data streams support Encryption,
Compression, Authentication and secure Java
computing.
• Many critical technologies relying on serialization.
www.edureka.co
12. DISADVANTAGES
• Objects while Deserialization becomes brittle.
• Serialization results in the failure in the initialization of
transient variables resulting in a variation to the
Standard Java Flow.
• Serialization is inefficient in terms of memory
utilization.
• Serialization does not offer any transition control
mechanism per every SE.
• Serialization procedure fails to offer fine-grained
control to access Objects.
www.edureka.co
20. www.edureka.co
• While using Externalizable Interface the user
explicitly mentions the objects to be serialized.
• In Serialization Interface, all the objects and variables are
serialized in the run-time.
IMPLEMENTATION
21. www.edureka.co
• Externalizable interface consists of two methods, namely:
writeExternal()
readExternal()
• Serializable Interface does not include any methods.
METHODS
22. www.edureka.co
• Externalizable Interface provides customization to the
Serialization process.
• Serialization Interface will provide the default serialization
process.
PROCESS
23. www.edureka.co
• Externalizable Interface supports Serialization
regardless of the version control.
• Serialization Interface requires the same version of
JVMs on both the ends, but it incorporates automatic
serialization.
BACKWARD COMPATABILITY
24. www.edureka.co
• Externalization Interface needs Public No-Arg Constructor to
reconstruct the serialized object.
• Serialization Interface uses reflection to reconstruct the
serialized object or class.
PUBLIC NO-ARG CONSTRUCTOR
27. www.edureka.co
TRANSIENT KEYWORD
Transient Keyword
Transient Keyword is used as a variable modifier at the time of
the Serialization process. Declaring a variable with transient
keyword avoids the variable from being Serialized.
TRANSIENTKEYWORD
29. www.edureka.co
SERIAL VERSION UID
Serializable objects get associated with a unique identification
number provided by the JVM of the host machine. This Unique
ID is called Serial Version UID.
SERIALVERSIONUID
31. www.edureka.co
WHAT IS AN INHERITANCE?
Oracle’s Architects intend to remove Serialization from Java as
they consider it as a Horrible Mistake of 1997.
After hectic research, the developers at Oracle found out a few
flaws in the design of Serialization procedure which pose a
threat to the data.
33. BEST PRACTICES
• It is recommended use javadoc@ serial tag for
denoting Serializable fields.
• The .ser extension is preferred to be used for files
representing serialized objects.
• It is not recommended for any static or transient
fields to undergo default serialization.
• Extendable classes should not be Serialized unless it
is mandatory.
• Inner Classes should be avoided to be involved in
Serialization.
www.edureka.co