Is there any difference between Serializalble and Externalizable interface?

Asked by Last Modified  

10 Answers

Learn Java

Follow 0
Answer

Please enter your answer

http://www.codingeek.com/java/io/differences-serializable-externalizable-interface-java-tutorial
Comments

Trainer

Serializalble is a marker interface, where as Externalizable is a interface, contains two methods writeExternal() and readExternal(). Externalizable interface is fast and also consumes less memory. Serializable involves reflection mechanism to recover the object. A public no-arg constructor is needed...
read more
Serializalble is a marker interface, where as Externalizable is a interface, contains two methods writeExternal() and readExternal(). Externalizable interface is fast and also consumes less memory. Serializable involves reflection mechanism to recover the object. A public no-arg constructor is needed while using Externalizable interface but in Serializable it reads the required information from the ObjectInputStream and this is why it uses reflection mechanism. read less
Comments

B.E. (IT)

by implementating java.io.Serializable, you get "automatic" serialization capability for objects of your class. No need to implement any other logic, it'll just work. The Java runtime will use reflection to figure out how to marshal and unmarshal your objects. In earlier version of Java, reflection...
read more
by implementating java.io.Serializable, you get "automatic" serialization capability for objects of your class. No need to implement any other logic, it'll just work. The Java runtime will use reflection to figure out how to marshal and unmarshal your objects. In earlier version of Java, reflection was very slow, and so serializaing large object graphs (e.g. in client-server RMI applications) was a bit of a performance problem. To handle this situation, the java.io.Externalizable interface was provided, which is like java.io.Serializable but with custom-written mechanisms to perform the marshalling and unmarshalling functions (you need to implement readExternal and writeExternal methods on your class). This gives you the means to get around the reflection performance bottleneck. In recent versions of Java (1.3 onwards, certainly) the performance of reflection is vastly better than it used to be, and so this is much less of a problem. I suspect you'd be hard-pressed to get a meaningful benefit from Externalizable with a modern JVM. Also, the built-in Java serialization mechanism isn't the only one, you can get third-party replacements, such as JBoss Serialization, which is considerably quicker, and is a drop-in replacement for the default. A big downside of Externalizable is that you have to maintain this logic yourself - if you add, remove or change a field in your class, you have to change your writeExternal/readExternal methods to account for it. In summary, Externalizable is a relic of the Java 1.1 days. There's really no need for it any more. read less
Comments

Senior Software Engineer

To add to the other answers, by implementating java.io.Serializable, you get "automatic" serialization capability for objects of your class. No need to implement any other logic, it'll just work. The Java runtime will use reflection to figure out how to marshal and unmarshal your objects.
Comments

Computer Trainer

Serializable Interface is based on a recursive algorithm i.e during the serialization besides the fields it will serialize all the objects that can be reached through its instance variables i.e. all the objects that can be reached from that object (provided that all the classes must implement Serializable...
read more
Serializable Interface is based on a recursive algorithm i.e during the serialization besides the fields it will serialize all the objects that can be reached through its instance variables i.e. all the objects that can be reached from that object (provided that all the classes must implement Serializable Interface). This includes the super class of the object until it reaches the “Object” class and the same way the super class of the instance variables until it reaches the “Object” class of those variables. Basically all the objects that it can read. And this leads to a lot of overhead when we want to save only few variable or a small data as compared to the class For eg – If you have a class named Mercedes and you just want to store the car series and its car identification number then you can not stop at this only and will have to store all the fields of that class and also of its super class(if exists and implements serializable interface) and a lot more. Serializable is a marker interface and hence no need to override any method and whenever there is any change in the entity or bean classes you just need to recompile your program whether in the case of Externalizable interface you have to implement writeExternal() and readExternal() methods which contains the logic to store and retrieve data and with changes you might need to do changes in the code logic. Serializable provides you both options i.e. you can handle the process by your own or you can leave it for the process to be done in the default way but in Externalizable you have to provide the logic of the process and have full control over the serialize and deserialize process. Serializable involves reflection mechanism to recover the object. This also adds the the metadata i.e. class description, variable information etc of all the serializable classes in the process which adds a lot of data and metadata into the stream and consumes bandwidth and a performance issue. A public no-arg constructor is needed while using Externalizable interface but in Serializable it reads the required information from the ObjectInputStream and this is why it uses reflection mechanism. You need to define serialVersionUID in case of Serializable and if it is not explicitly defined it will be generated automatically and it is based on all the fields, methods etc of the class and it changes every time you do the changes in the class. You if current id does not match with generated id you will not be able to recover the previously stored data. Since the ID is generated every time it will take considerable amount of time which is not a case with externalizable interface. Externalizable interface is fast and also consumes less memory as compared to the other one. read less
Comments

Difference between Externalizable and Serializable In case of Serializable, default serialization process is used. while in case of Externalizable custom Serialization process is used which is implemented by application. JVM gives call back to readExternel() and writeExternal() of java.io.Externalizalbe...
read more
Difference between Externalizable and Serializable In case of Serializable, default serialization process is used. while in case of Externalizable custom Serialization process is used which is implemented by application. JVM gives call back to readExternel() and writeExternal() of java.io.Externalizalbe interface for restoring and writing objects into persistence. Externalizable interface provides complete control of serialization process to application. 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. read less
Comments

Java Trainer

Serializable provides default serialization(takes care by JVM) whereas Externalizable is used for customized serialization(Everything takes care by the programmer. When we implement Serializable interface , total object is saved but in case of Externalizable, programmer can save total object or part...
read more
Serializable provides default serialization(takes care by JVM) whereas Externalizable is used for customized serialization(Everything takes care by the programmer. When we implement Serializable interface , total object is saved but in case of Externalizable, programmer can save total object or part of the object. Serializable is a marker interface(does not contain any method whereas Externalizable contains writeExternal() and realExternal() methods. read less
Comments

Expert in Java/J2ee technology

Serializable Interface has its own standard protocol to implement serialization capability. But implementing Externalizable interface developer needs to implement writeExternal and readExternal methods. Externalizable extends Serializable.
Comments

Senior Software Engineer

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...
read more
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. read less
Comments

Trainer

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...
read more
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. read less
Comments

View 8 more Answers

Related Questions

I know HTML, CSS, and a bit of JavaScript. What should I learn next?
HTML,CSS and Javascript are Tools which are used for Front-End Web Development. The next step is to learn the following: 1)Learn Javascript Frameworks like node.js,react.js,angular.js etc. 2)Learn Back-End...
Inch By
What is difference between throw and throws in Java programming?
throw keyword is used to throw Exception from any method or static block in Java while throws keyword, used in method declaration, denoted which Exception can possible be thrown by this method
Vinodha
When we are used the compiler and interpreter? what is the difference between them?
compiler compiles whole page or file at one time but interpreter executes line by line like we do using debugger
Shilpa
Which language has the best future prospects: Python, Java, or JavaScript?
According to me, "Python" is the programming language having the best future prospect considering the current industry trend. Reason: Python is extensively used in advanced technologies such as Machine...
Atharva
0 0
5

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

How can everyone prepare to clear any Java interview?
Java interview your java should be much strong then J2EE. core java and Advance java is the basic foundation for Interview. Some of the topic about which you should know before going for a java interview...

Final modifier in Java
Can’t change value of variable if marked as final. It is best practice to mark method parameter as final if its value will not changes. Variable must be initialize either using Initializer block...

Java Learning Tip
The easy way to learn any programatical language is just simple practices. Take a simple examples and practice daily one hour. And also go through the learning videos from youtube or somewhere else.

Class and Objects in Java
Class is a template or a blueprint which is used to describe an object. On other hand Object is a reference of a class which follows all the stuff written inside the class. How about taking the whole tour in the following video

How To Setup development Environment Of Java?
After installation of JAVA, we need to setup 2 environment variables. First one is JAVA_HOME and second is Path. Below steps to set up Java environment to compile & execute Java programs from command...

Recommended Articles

Before we start on the importance of learning JavaScript, let’s start with a short introduction on the topic. JavaScript is the most popular programming language in the world, precisely it is the language - for Computers, the Web, Servers, Smart Phone, Laptops, Mobiles, Tablets and more. And if you are a beginner or planning...

Read full article >

Java is the most commonly used popular programming language for the creation of web applications and platform today. Integrated Cloud Applications and Platform Services Oracle says, “Java developers worldwide has over 9 million and runs approximately 3 billion mobile phones”.  Right from its first implication as java 1.0...

Read full article >

Java is the most famous programming language till date. 20 years is a big time for any programming language to survive and gain strength. Java has been proved to be one of the most reliable programming languages for networked computers. source:techcentral.com Java was developed to pertain over the Internet. Over...

Read full article >

In the domain of Information Technology, there is always a lot to learn and implement. However, some technologies have a relatively higher demand than the rest of the others. So here are some popular IT courses for the present and upcoming future: Cloud Computing Cloud Computing is a computing technique which is used...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you