Understanding of the serialization of Java objects

Source: Internet
Author: User

The transient variable at serialization in 1.java (the function of this keyword is to tell Java that I cannot be serialized) and that static variables are not serialized (here is an example of a test)

(Solid with Versionuuid, easy to deserialize without error.) )

2. It is also most important to note that if you serialize the object A after serialization B, then in the deserialization must remember that Java rules first read the object is first serialized object, do not receive object B First, that will be an error. Be sure to note when using the externalizable above The order in which they are read.

3. Objects that implement a serialized interface do not enforce a unique serialversionuid, declaring that Serialversionuid has a significant impact on the upward-downward compatibility of object serialization

In order to maintain version compatibility when serializing, that is, deserialization still preserves the uniqueness of the object during version upgrade

The purpose of the general manifested serialization is two, the first one is easy to store, the second is easy to transfer. You can read and write to this class only if you serialize the class

First: Is there a corresponding data structure in the storage media?

Second: Does this entity class need to be remotely transmitted (or is it a call between two different systems or even distributed modules for NoSQL)?

Using Java object serialization, when you save an object, it saves its state as a set of bytes, and in the future, these bytes are assembled into objects. It is important to note that object serialization holds the "state" of the object, which is its member variable. It is to be concluded that object serialization does not focus on static variables in the class.

In addition to using object serialization when persisting objects, object serialization is used when RMI (remote method calls) is used, or when objects are passed through the network.

Either implementing the Serializable interface or the Externalizable interface, the Readresolve () method is called when the object is read from the I/O stream. The object that was created in the deserialization process is replaced directly with the object returned in Readresolve ().

After serialization, it translates into a set of bytes that can be accessed on the network by the person he is.

private transient String name;//Declares the Name property, but this property is not serialized

Use:

1, before just know serialization, you can use IO stream to serialize and deserialize objects, access;

The file stream is used to store the object, and if the object is not serialized, an error is made:

Java.io.NotSerializableException:com.rfcd.distribution.serviceImpl.Person

2, the object is converted into a set of byte, so that in the future to use this object, you will be able to restore the byte data, and then rebuild that object (automatic compensation for operating system differences.) That is, you can create a key object on the Windows machine, serialize it, then upload it to the UNIX machine via the network, and then rebuild it there.

3, through the "will do the serialization of the processing of the object written to disk, wait until the program run again when it read out", you can achieve persistence effect.

4. The Java Remote method call (invocation) allows you to invoke objects on other machines as you would call objects on your own machine.

Understanding of the serialization of Java objects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.