Retrieved from https://studentshare.org/logic-programming/1631982-programming-iii-advanced
https://studentshare.org/logic-programming/1631982-programming-iii-advanced.
The process of serialization and deserialization is independent of the platform used, that is, data serialized on one machine can be deserialized on a completely different machine with a different platform (D'Anjou, 2005).
Serialization in java has been used mainly to facilitate communication between different machines, for persistence, deep copying, caching, and cross java virtual machine synchronization. The use of serialization is advantageous since it allows for refactoring, it is customizable and easy to use, and allows encryption, compression, and authentication thus facilitating secure computing lastly, the mechanism allows the interchange of libraries between java and other programming languages such as C++ among other advantages.
Despite the above-stated functions and advantages of serialization in java, there are too many disadvantages associated with serialization. Serialization offers significant overhead thus it cannot be used with large objects. Also, serialization facilitates increased memory requirements for a system. The use of data serialization also leads to the breakage of the identity of objects, and the invasion of the programming model. To address the disadvantages and limitations of serialization, an input/output process mechanism has been introduced. This mechanism is referred to as Externalization. Not only is Externalization used to eliminate the limitations of serializations, but also in some cases, it is exclusively required.
Externalization refers to the process in which an externalizable interface is implemented to facilitate the persistence and restoration of the object the externalizable interface works by extending the serializable interface. Moreover, the externalizable interface facilitates the definition of custom rules and also, the definition of a customizable serialization mechanism. Thus, it can be easily said that externalization is an extension of serialization. The process of using Externalization is similar to the implementation process of externalization.
The serialization mechanism’s serializable interface is by default serialized while in Externalization, there is a provision on the interface that facilitates complete control over the process of serialization. This makes externalization to be more advanced than serialization. The Externalizable interface consists of two methods, the public void readExternal (ObjectInput in) and the public void writeExternal (ObjectOutput out). In externalization, the process of serialization is extended by the addition of readExternal, and write External. The use of these two classes ensures that they are called automatically during deserialization and serialization thus ensuring full control of the entire serialization and deserialization process.
The major difference between serialization and externalization is when using externalization, there is full control over the reading and writing process. This is achieved by the implementation of write external methods and read external methods. Also, another difference arises in that in externalization, there is custom serialization while in serialization, there is the use of the default process of the serialization i.e., the inbuilt serialization mechanism.
The advantage of serialization can be summarized into two major advantages:
- There is an extreme reduction in the file size as compared to serialization.
- The use of externalization facilitates customization which is very effective, efficient, and easy.