Minggu, 30 Maret 2014

Difference between Serializable and Externalizable in Java Serialization




Difference between serializable and externalizable is popular java interview question which we have touched on my earlier post on Serialization: Top 10 java serialization interview questions. knowing differences between externalizable and serializable is not just important from interview point of view but also getting control of serialization process and optimizing performance of serialization. both serializable and extenalizable used to serialize or persist java objects but the way they do is little different. In case of Serializable Java Virtual machine has full control for serializing object while in case of Externalizable, application gets control for persisting objects. writeExternal() and readExternal() method provides complete control on format and content of Serialization process to application which can be leverage to increase performance and speed of serialization process.







Serialization and Externalization in Java




Serializable vs Externalization in Java



difference between Java Serialization vs Externalization in Javahere are some more differences between Serializable and Externalizable interface in Java:





1. In case of Serializable, default serialization process is used. while in case of Externalizable custom Serialization process is used which is implemented by application.





2. JVM gives call back to readExternel() and writeExternal() of java.io.Externalizalbe interface for restoring and writing objects into persistence.





3. Externalizable interface provides complete control of serialization process to application.





4. readExternal() and writeExternal() supersede any specific implementation of writeObject and readObject methods.





Though Externalizable provides complete control, it also presents challenges to serialize super type state and take care of default values in case of transient variable and static variables in Java. If used correctly Externalizable interface can improve performance of serialization process.








That’s all on Difference between Externalizable and Serializable interface in Java. This is always asked when Java interview take turn towards Serialization after Multi-Threading questions and Collections Interview questions. Only problem with Serialization is that not many programmer use it and that’s why it look little difficult otherwise once you familiar with Serialization process and rules of Serialization, interview questions can be more easily handled.








Some Interview Questions post:































Source:http://javarevisited.blogspot.com/2012/01/serializable-externalizable-in-java.html

Tidak ada komentar:

Posting Komentar