Serializable and externalizable
Hi all,
What is the diffrence between the externalizable and serializable and when do we use each one of them ?
Thanks in advance
Harish
Both are interfaces with Externalizable extending Serializable. However where Serializable is a tagging interface (an interface with no methods to implement) Externalizable contains two methods to implement: readExternal and writeExternal. Use Serializable when you require default serialization (i.e., all non-transient, serializable attributes of a class and it's superclass(es) are serialized). Use Externalizable when you require complete control over the serialization process (i.e., you determine what attributes to serialize and how far up the hiearchical chain to traverse although this can be achieved via the Serializable interface as well by providing implementations of the ObjectInputStream and ObjectOutputStream class's readObject and writeObject methods respectively).
Similar Messages
-
Difference between serialization and externalization
Can any body explain me the difference between serialization and externalization
with some example.Have you tried google?
Serializable indicates that the object can be serialized by the default serializer, Externalizable means that the object itself will handle the serialization of the object.
/Kaj -
Difference between Serialization Vs Externalization
hi can anyone tell me Difference between Serialization Vs Externalization
Serialization is the process of converting an object into a sequence of bits so that it can be persisted on a storage medium (such as a file, or a memory buffer) or transmitted across a network connection link. This process of serializing an object is also called deflating or marshalling an object.
The serialization mechanism has been added into the Java language for two reasons:
(1) the JavaBeans mechanism uses serialization.
(2) remote method invocation (RMI) allows you to automatically use objects located at another host in the network just like any local objects.
In order to serialize an object, you need the output stream OutputStream, which must be put into the special serialization stream called ObjectOutputStream. After that, you only need to call the method writeObject() to serialize the object and send it to the output stream. . Classes ObjectInputStream and ObjectOutputStream, which respectively implement the ObjectInput and ObjectOutput interfaces, enable entire objects to be read from or written to a stream (possibly a file). To use serialization with files, we initialize ObjectInputStream and ObjectOutputStream objects with stream objects that read from and write to files—objects of classes FileInputStream and FileOutputStream, respectively
Vinayworld class implements serializable interface.
Other class would be
In this code object of the vinayworld class is serialized into a file name vinay.txt
Serialization is a Marker interface -Marker Interface is used by java runtime engine (JVM) to identify the class for special processing.
Use serialization when you need to add data to the serialization stream that is not an object data member.
Externalization is same as Sterilization except that WriteObject() and ReadObject() method are called by JVM during sterilization an desterilization of object. One thing you can do with Externalization is that you can store extra information into object like STATIC variables and transient variables or you can add more information if you have any business need. One good example is compressing and uncompressing of data to send it through network or converting one format to other like a BMP image to JPEG or GIF format.
Externalization allows you to customize how serialization is done. By implementing externalization you are controlling what gets serialized ( and what doesnot ) as versus default serialization where all non-transient attributes get serialized.
For “fat data” classes with a large number of attributes only a few of which needs to persisted, externalization will help you reduce the size of serialized stream and the time taken to serialize the object. But there will be an overhead involved because the runtime has to call your methods to read/write objects.
Read more: http://www.techartifact.com/blogs/2009/06/serialization-vs-externalization.html#ixzz2mWAYCMRz -
Serializable vs Externalizable ?
Hi,
I try to build a RMI server that initiate a connection. The
client uses this RMI server connection. When he needs to execute
statements, the RMI server also instantiate a class for the
client whose execute them. At this moment, the RMI server give
me this error:
profile DataManagement.DMLoginImpl_SJProfile0 not found:
java.io.InvalidClassException: [Ljava.lang.Object;; Serializable
is incompatible with Externalizable
Where DataManagement.DMLoginImpl_SJProfile0 is the Profile.
I use JDK 1.2 with SQLJ 8.1.5.
Need help !
Thanks
Daniel
nullSerializable is simpler to implement (The minimum is to just "implements Serializable) and simpler to extend (e.g. it manages inheritance)
Externalizable gives you most control, but you have to do more yourself.
If you are starting out, just use Serializable. It turns out to be inadequate then you can convert the classes which need Externalizable to be be those.
Note: You don't have to just use one or the other. -
MTS with batch management, serialization and Handling unit
Hello All,
I am testing a scenario for MTS with batch management, serialization and Handling unit for discrete manufacturing.
Everything worked fine till I created the Handling unit for the finished product.
The production order has a quantity of 3 EA.
It has three serial numbers 1, 2 and 3. (serial numbers can be displayed from order->Header->serial numbers)
I created one Handling unit for production order quantity of 3 EA.
I tried to do a goods receipt for the production order using transaction COWBHUWE.
I get the following error when I try to post the GR:
Only 0 serial numbers entered instead of 3
Message no. IO304
Diagnosis
There is a serial number obligation, so the number of serial numbers must equal the number of serial numbers in the material document.
You can post the operation only if you entered the correct number of serial numbers previously.
System Response
Depending on the context in which the error arises, the system continues processing, or the required function cannot be performed.
Procedure
You have the following options, for example:
Check that the serial numbers are entered fully.
If necessary, display an error log.
If necessary, contact your system administrator.
What did I miss?
How to fix this problem?
Please help.
Thanks in advance
GeorgeI added the serialization procedure HUSL to the serial number profile and it fixed the problem.
-
Revision: 22429
Revision: 22429
Author: [email protected]
Date: 2011-09-07 08:04:46 -0700 (Wed, 07 Sep 2011)
Log Message:
Adding the default fallback of serializer and deserializer classes to amf deserializer and amf serializer
Modified Paths:
blazeds/trunk/modules/core/src/flex/messaging/io/SerializationContext.java -
Diff between Serialization and Synchronization
Hi I am new to java.
Pl. give me the difference between Serialization and Synchronization.
Thankq
SridharDon't you look at the timestamps of posts? They could
have been typing at the same time.
/KajPlease stop! I'll die laughing. LOL
Re: Diff between Serialization and Synchronization
Author: Annie. Apr 11, 2005 10:30 AM (reply 1 of 4)
Re: Diff between Serialization and Synchronization
Author: glrao Apr 12, 2005 8:31 AM (reply 2 of 4) I really like your sense of humor.
xH4x0r -
Diff between Serialization and Synchonization
Hi I am new to java.
Pl. give me the difference between Serialization and Synchonization.
Thankq
SridharPl. give me the difference between Serialization and
Synchonization.Object serialization is the process of saving an object's state to a sequence of bytes, as well as the process of rebuilding those bytes into a live object at some future time. The Java Serialization API provides a standard mechanism for developers to handle object serialization.
Synchronization is intended to make the code thread safe by setting locks on objects.
They are totally different concepts. I fail to understand how you intend to compare them. -
Singleton serialization and weblogic - help!
hi everyone,
I'm trying to serialize a singleton cache object we're using for our (intranet)
website running on weblogic 6.1. I've made sure the singleton class
implements serializable, and i've also put the following method in the
singleton class (ChartCache.java):
private Object readResolve()
return theInstance; //which is of type ChartCache
By the way I'm using jdk 1.3. I've trawled the web and can't find anything to help me yet...
Basically I've written a jsp to get the current instance of the cache
and serialize it to a file. When I invoke another jsp i want it to
reinflate the object and place it back into the weblogic jvm so it can
once again be accessed as a singleton by all classes in the webapp. At
the moment its just not working - the cache object will eventually
take over half an hour to create (huge database processing going on)
so I want the option, if weblogic falls over, to reinstantiate the
cache without having to rebuild it from scratch. The cache will only
be refreshed once a day.
I'll c&p my jsp code below...
======================= restoreCache.jsp
<%@ page import = "java.util.*" %>
<%@ page import = "java.io.*" %>
<%@ page import = "com.drkw.agencylending.website.chartcache.*" %>
<%@ page import = "com.drkw.agencylending.log.Logger" %>
<%
ChartCache theCache = null;
try
String filename = "chartCache.dat";
FileInputStream fis = new FileInputStream(filename);
ObjectInputStream in = new ObjectInputStream(fis);
theCache = (ChartCache)in.readObject();
in.close();
catch(Exception e)
Logger.log(e);
%>
Resurrected chart cache from file.
======================= saveCache.jsp
<%@ page import = "java.util.*" %>
<%@ page import = "java.io.*" %>
<%@ page import = "com.drkw.agencylending.website.chartcache.*" %>
<%@ page import = "com.drkw.agencylending.log.Logger" %>
<%
ChartCache theCache = ChartCache.getInstance();
String fileName = "chartCache.dat";
try
FileOutputStream fos = new FileOutputStream(fileName);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(theCache);
oos.flush();
oos.close();
catch(Exception e)
Logger.log(e);
%>
Wrote cache object to file.
============================
At the moment, a file is getting written but it seems suspiciously
small (73 bytes!) for what is a very large object. When I try to load
it up again, I get no errors but when I call ChartCache.getInstance()
(my singleton) it recreates the cache rather than using the one I've
reinflated. BTW I don't need to worry about server clustering/JNDI to
ensure I have a truly singleton instance - there will only ever be one
JVM to worry about.
Any help greatly appreciated!solved the problem using another technique. Rather
than serialize the entire singleton object, I just
serialized the hashmap (the only bit I really care
about). Then in the private constructor, the class
checks a database flag to see whether the singleton
was created today - if not, I refresh the cache,
otherwise load in the serialized hashmap and set that
as my class member. No complicated jndi/ejb registry
needed to get around it..!singleton serialization is not recommended in ejb enviroment, it will cause problems. in what you are doing, it is far better to persist the data values in a database.
just for the sake of writing a serializable sington: in addition to what you do in a regular object, you would first check to see if this obj has been serialized, if it is, deserialize it and return this one. you would have to write your own method to do serialization, making sure you have only one place to serialize it, and let the object know where the file is. -
Using serialize and deserialize methods generated by clientgen
I am trying to use the classes generated by the weblogic.webservice.clientgen tool
from the weblogic 8.1 release. I would like to be able to make direct use of
the serialize and
deserialize methods in the "Codec" classes that correspond to the various request
and
response object classes. However, these methods require SerializationContext
and
deserializationContext objects as inputs. Are these context objects things I
can construct,
manufacture and/or access? Are there any coding examples for using these methods?
Thanks.
MichaelBruce,
Thanks for the response. I have seen the documentation before. What that shows
me is how
to write customized Serialize and Deserialize methods. What I want to do is call
the ones that
clientgen has already created for me. I would love to have these called by the
internals of the
generated code as part of the handling of service calls. My problem is that the
web site
that I'm calling for these services uses SSL, and every attempt to use the clientgen-generated
services results in the following exception being raised:
javax.net.ssl.SSLKeyException: FATAL Alert:BAD_CERTIFICATE - A corrupt or unuseable
certificate was received.
Since I am successful in making SOAP calls to this same site -- certificate aren't
an issue
for these SOAP calls -- I thought that what I should try is to make the service
calls myself
using SOAP, but to use the generated Serialize and Deserialize methods
to create the request body and process the response body surrounding the SOAP
call.
However, what I'd really like to do
is figure out the cause of the SSLKeyException, and to make the service calls
the way weblogic
intended them to be made. So if you have any suggestions about what might
be causing the exception, I'd appreciate the help.
BTW. In addition to being able to make SOAP calls myself, I've also had some success
making
web service calls using code generated by Apache AXIS's wsdl2java tool and JWSDP's
wscompile
tool; however, neither of these wsdl processors are replacements for clientgen
because they
both have problems dealing with the complex structures described by wsdl files
for the web
services I'm trying to use.
Bruce Stephens <[email protected]> wrote:
Hi Michael,
The De/SerializationContext are internal/private objects. The example
in the doc (you have probably already seen) is a good starting point:
http://e-docs.bea.com/wls/docs81/webserv/customdata.html#1052981
Regards,
Bruce
BTW, Have you considered using XMLBeans?
http://dev2dev.bea.com/technologies/xmlbeans/index.jsp
Michael Horton wrote:
I am trying to use the classes generated by the weblogic.webservice.clientgentool
from the weblogic 8.1 release. I would like to be able to make directuse of
the serialize and
deserialize methods in the "Codec" classes that correspond to the variousrequest
and
response object classes. However, these methods require SerializationContext
and
deserializationContext objects as inputs. Are these context objectsthings I
can construct,
manufacture and/or access? Are there any coding examples for usingthese methods?
Thanks.
Michael -
Regarding Serializable and subclasses.
I have a an abstract parent class called 'Information'
which implements Serializable and which has an abstract
method called init().
There are 2 subclasses that extend the parent class Information
called SInformation_1 and SInformation_2 and implement the method init().
Now as the parent class is Serialized,will the concrete subclasses
also be Serializable?How long does it take to write a demo?
import java.io.*;
abstract class Base implements Serializable {
public abstract void init();
class D1 extends Base {
public void init() {}
class D2 extends Base {
public void init() {}
public class SerializableExample {
public static void main(String[] args) throws IOException, ClassNotFoundException {
Base obj1 = new D1();
Base obj2 = new D2();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(baos);
out.writeObject(obj1);
out.writeObject(obj2);
out.flush();
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream in = new ObjectInputStream(bais);
D1 d1 = (D1) in.readObject();
D2 d2 = (D2) in.readObject();
} -
Hi everyone:
I just want to know, say if you serialize an Object, obviously, the object will be stored in memory. But let us say if you deserialize it later on,
will the object be clean by the Garbage Collector?Your question suggests you might misunderstand the terms serialize and deserialize. You serialize an object to send it to another computer or store it out of memory, for example in a file. The serialized object can then be deserialized back into an in-memory object. Did you already know that, or does that help clear it up?
-
Serialize and Deserialize with Oracle 9 and Oracle 10
We have developed a client/server application. Client is a Java application and Server is written in C-Language; link between Java and C is RPC/JRPC.
We have to serialize and then deserialize a stream in a clob field in Oracle DB. When we deserialize with Oracle 9 we have no problem; now, after a migration to Oracle 10G, the deserialize failed at client level.
If we test in test environment (Oracle 9) with the same client and the same server we have no problem. The only difference between two enviroenment is only the version of Oracle (9 is OK - 10G is KO).
We use the OCI api.
The error message at client level is:
java.io.InvalidClassException: rpc.wDichiarazione; local class incompatible: stream classdesc serialVersionUID = 2960125282182152041, local class serialVersionUID = 2960125281578161001
Thanks of all
MarcoYou've changed a class definition. It has nothing to do with the Oracle version. Recompile that class with
private static long serialVersionUID = 2960125282182152041L;If you then get another exception, you need to evaluate the changes you've made to the class in the light of what it says about Versioning in the Serialization specification. -
Serialization and Class Integration
I have a class that I want to serialize in order to save it to a file. In terms of OO design what is the best way to go about integrating serialization into my classes?
I was going to have two static methods that would read/write an object of the class from/to a stream, where both the stream and object are paramters to the method. Would it make sense to implement it this way or would it be considered messy?
Thanks!All you have to do is add implements java.io.Serializable to the class definition and make sure that any non-static non-transient data members are also serializable (and so on recursively until closure).
-
Serialization and circular dependancies
I am hoping to save some objects using serialization. However, I am worried about some circular dependacies.
I have a list of authors and books. Each book is associated with an author. And each other has a list of books. Therefore there is a circular depedancy in that in each author is a reference to a book which has a reference to the author.
Does std serialization take care of this or does it cause a problem?
Thanks.I am hoping to save some objects using serialization.
However, I am worried about some circular
dependacies.
I have a list of authors and books. Each book is
associated with an author. And each other has a list
of books. Therefore there is a circular depedancy in
that in each author is a reference to a book which
has a reference to the author.
Does std serialization take care of this or does it
cause a problem?What happened when you wrote a little program to test this?
Did it create an infinitely large file? Were you able to serialize and deserialize successfully?
Maybe you are looking for
-
Color issues when printing AI files on PostScript
First off, please forgive me if this is not the right forum or if I am not using the right terms. I am the network admin for our company and I'm posting this on behalf of our designer. We recently added PostScript drivers to our Sharp printers, and
-
Is this an issue because of the new IOS.
-
My Ipad isnt allowing me to charge it. It shows red and the lightening bolt. It then shows me the message to hook up to itunes. When i do that, I am getting a message that says the ipad needs to be restored. When I attempt to restore, itunes is n
-
La muminosité de mon imac baisse sans que je puisse la réaugmenter. Le témoin de luminosité reste à l'écran. Les touches F1 et F2 ne foctionnent pas. Dans les préférences système, lorsque je déplace le curseur, il revient automatiquement au mini.
-
Proper database reqd for E71 - suggestions please
I have to keep a list of my customers and the jobs I do for them with me at all times. I have approx 2000 customers with an average of 4 jobs each. This will obviousl;y grow as time goes on (hopefully!) Currently, thi sis all kept on a Psion series 5