The function of entity class to realize serializable

Source: Internet
Author: User
Tags serialization

Serializable, has been used before, the default entity class will implement the Serializable interface, for the specific reason has not been very understanding, and if not implemented serialization, also has no effect, when should be serialized operation. Today, I looked up the data and summed up the general.

1, in fact, serialization, it is a complete preservation of a state of the object information, is a whole, rather than fragmented. I saw a statement in an IBM Engineer's blog that I felt was helpful in understanding serialization, and he said that the process of serialization was a "freeze" process that freeze an object and then stored it until it was needed again. This object is De-freeze and can be used immediately.

2, and like int, long, Boolean type, etc., are basic data types, the database has the corresponding data structure. From the class declaration, what we think is not serialized, in fact, is in the declaration of the different variables, by the specific data types to help us achieve serialization operations. So even if we do not implement serializable can still operate normally.

At this point, there is a problem, since the entity class variables have helped us achieve serialization, why we still want to show the class implementation serializable interface.

First, there are two purposes for serialization, the first is easy to store, and the second is easy to transfer. When our general entity classes do not require programmers to serialize again, think of two questions: first: whether there is a corresponding data structure in the storage medium. Second: The entity class, whether it requires remote transmission (or two different systems or even a call between distributed modules).

If you notice that the serialization operation is used for storage, it is generally for the NoSQL database, while using the NoSQL database for storage, the "freeze" to understand the argument is more appropriate, please in the NoSQL database, find me a varchar, int sort of data structure out. If not, but we do need to store, then the programmer does not serialize the object, the more time to wait.

Note: If someone opened the source code of the serializable interface, it will be found that the interface is actually an empty interface, then this serialization operation, in the end is by WHO to achieve it. In fact, look at the annotation of the interface to know that when we let the entity class implement the Serializable interface, is actually telling the JVM that this class can be serialized, can be serialized by the default serialization mechanism.

Then, it should be explained that when we implement the serializable interface in the entity class declaration, we see that these classes need to be invoked remotely. This means that you need or may need to be called remotely, which is the purpose of serialization for easy transmission.


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.