Object Streams & Serialization
Object Streams & Serialization
AND
SERIALIZATION
Team 2
Serialization
WHAT IS SERIALIZATION ?
• A java object is serializable if its class or any of its super classes implements
java.io.serializable interface or its sub interface, java.io.externalizable.
• Serializable is a marker interface that adds serializable behavior to the class
implementing it.
• Marker interface is used as a tag to inform a message to the Java compiler
so that it can add special behavior to the class implementing it. Java marker
interface has no members in it.
Difference between serializable and externalizable
• Serializable is a marker interface i.e. does not contain any method but
Externalizable interface contains two methods writeExternal() and
readExternal().
• When any class in Java implement java.io.Externalizable than its your
responsibility to implement Serialization process i.e. preserving all important
information.
• Performance.
Example of java serialisation
Advantages
• Easy to use and customized.
• The byte stream created is platform independent. So, the object serialized on
one platform can be deserialized on a different platform.
• Serialized stream can be encrypted, authenticated and compressed supporting
needs of secure java computing.
• It can be used for exchanging objects between java and c++ libraries using
third party libraries.
Disadvantages
• It should ideally not used with large sized objects, as it offers overhead.
• Doesn’t offer fine grained control over object access.
• Doesn’t offer any transaction control mechanism.
Object streams
OBJECT STREAMS
• Object stream classes are object input stream and object output stream.
• These classes implement object input and object output which are sub
interfaces of data input and data output.
Byte streams
• Java byte streams are used to perform input and output of 8- bit bytes.
• Though there are many classes related to byte streams but most frequently
used classes are FileInputStream and FileOutputStream.
FileInputStream
• FileReader is useful to read data in the form of characters from a ‘text’ file.
• This class inherit from the InputStreamReader Class.
• The constructors of this class assume that the default character encoding and
the default byte-buffer size are appropriate. To specify these values yourself,
construct an InputStreamReader on a FileInputStream.
• FileReader is meant for reading streams of characters. For reading streams of
raw bytes, consider using a FileInputStream.
Uses of streams
• Main reason for the use of streams is to make your code simpler and easy to
read.
• The goal of streams in Java is to simplify the complexity of writing parallel
code.
• It's inspired by functional programming.
• The serial stream is just to make the code cleaner.
THANK YOU