This link has been bookmarked by 70 people . It was first bookmarked on 15 Jul 2006, by CK Lee.
-
05 May 12
-
12 Apr 12
-
13 Mar 12
-
Williams RivasDiscover the secrets of the Java Serialization API
-
02 Sep 11
-
Because
readObject()can read any serializable object, a cast to the correct type is required. With that in mind, the class file must be accessible from the system in which the restoration occurs. In other words, the object's class file and methods are not saved; only the object's state is saved. -
. The trick here is that the virtual machine will automatically check to see if either method is declared during the corresponding method call. The virtual machine can call private methods of your class whenever it wants but no other objects can. Thus, the integrity of the class is maintained and the serialization protocol can continue to work as normal.
-
To stop the automatic serialization, you can once again use the private methods to just throw the
NotSerializableException. -
If you wish to control versioning, you simply have to provide the
serialVersionUIDfield manually and ensure it is always the same, no matter what changes you make to the classfile. Y -
The version control works great as long as the changes are compatible. Compatible changes include adding or removing a method or a field. Incompatible changes include changing an object's hierarchy or removing the implementation of the
Serializableinterface.
-
-
11 Aug 11
-
15 Jul 11
-
0 import java.io.Serializable;
20 import java.util.Date;
30 import java.util.Calendar;
40 public class PersistentTime implements Serializable
50 {
60 private Date time;
70
80 public PersistentTime()
90 {
100 time = Calendar.getInstance().getTime();
110 }
120
130 public Date getTime()
140 {
150 return time;
160 }
-
-
16 May 11
-
21 Apr 11
-
21 Mar 11
-
10 Feb 11
-
29 Nov 10
-
03 Aug 10
-
02 Aug 10
-
02 Jul 10
-
implements Serializable
-
Node streams can be used to write to file systems or even across sockets. That means we could easily transfer a flattened object across a network wire and have it be rebuilt on the other side!
-
import java.io.ObjectOutputStream;
-
import java.io.FileOutputStream;
-
200 out.writeObject(time);
-
To restore the file
-
import java.io.ObjectInputStream;
-
import java.io.FileInputStream;
-
creates a live object that is an exact replica of the origina
-
a cast to the correct type is required.
-
the object's class file and methods are not saved; only the object's state is saved.
-
strings, and arrays -- are serializable
-
certain system-level classes such as
Thread,OutputStreamand its subclasses, andSocketare not serializable.
-
-
24 Jun 10
-
In other words, the object's class file and methods are not saved; only the object's state is saved.
-
The
java.lang.Objectclass does not implement that interface -
you must mark
transientany field that either cannot be serialized -
Serialization does not care about access modifiers such as
private-- all nontransient fields are considered part of an object's persistent state and are eligible for persistence. -
- Rule #1: The object to be persisted must implement the
Serializableinterface or inherit that implementation from its object hierarchy - Rule #2: The object to be persisted must mark all nonserializable fields
transient
- Rule #1: The object to be persisted must implement the
-
The virtual machine can call private methods of your class whenever it wants but no other objects ca
-
. That means that if the state of the written object is written and then written again, the new state will not be saved!
-
-
20 Apr 10
-
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.
-
three different ways to perform serialization -- using the default protocol, customizing the default protocol, and creating our own protocol
-
and we'll investigate concerns that arise with any persistence scheme such as object caching, version control, and performance issues.
-
The completely empty
Serializableis only a marker interface -- it simply allows the serialization mechanism to verify that the class is able to be persisted. Thus, we turn to the first rule of serialization: -
The
java.lang.Objectclass does not implement that interface. Therefore, not all the objects in Java can be persisted automatically.
-
-
17 Dec 09
Dan Chisarickprivate void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
java serialization tutorial programming api development howto serialize article
-
29 Nov 09
-
24 Sep 09
Vivek ViswanathanserialVersionUID, Externalizable
java tutorial programming serialization Externalizable Interview
-
19 Sep 09
-
07 Jun 09
-
26 Apr 09
-
21 Apr 09
-
09 Apr 09
-
Create Your Own Protocol: the Externalizable Interface
Our discussion would be incomplete not to mention the third option for serialization: create your own protocol with the
Externalizableinterface. Instead of implementing theSerializableinterface, you can implementExternalizable, which contains two methods: -
The identifier that is part of all classes is maintained in a field called
serialVersionUID.
-
-
21 Jan 09
-
16 Dec 08
-
08 Oct 08
-
01 Sep 08
-
11 Jul 08
-
03 Jul 08
-
21 May 08
-
30 Apr 08
-
29 Apr 08
-
31 Mar 08
-
15 Nov 07
-
16 Oct 07
-
13 Aug 07
-
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. The API is small and easy to use, provided the classes and methods are understood.
-
-
08 Aug 07
Leandro Rodrigo Saad Cruzeration for your application, you may want to consider building a custom protocol.
-
11 Jun 07
-
20 May 07
-
13 Apr 07
Isaac RuizDiscover the secrets of the Java Serialization API
API article example howto interface java programming serialization
-
24 Feb 07
-
04 Feb 07
-
the object's class file and methods are not saved; only the object's state is saved.
-
First, the object is checked to ensure it implements
Serializableand then it is checked to see whether either of those private methods are provided. If they are provided, the stream class is passed as the parameter, giving the code control over its usage -
To stop the automatic serialization, you can once again use the private methods to just throw the
NotSerializableException -
if the state of the written object is written and then written again, the new state will not be saved
-
First, you could make sure to always close the stream after a write call, ensuring the new object is written out each time. Second, you could call the
ObjectOutputStream.reset()method -
If you wish to control versioning, you simply have to provide the
serialVersionUIDfield manually and ensure it is always the same, no matter what changes you make to the classfile. -
the system may not garbage collect the objects written to a stream if the stream is not closed
-
-
12 Jan 07
-
25 Dec 06
-
24 Nov 06
-
27 Nov 05
-
05 Feb 05
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.