Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the knowledge points of Java serialization

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the Java serialization knowledge points", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "What are the Java serialization knowledge points"!

profile

Serialization saves Java object-related class information, attributes and attribute values, and deserialization constructs Java objects based on these information.

Serialization operations in Java require implementation of Serializable or Externalizable interfaces.

The role of serialization

Provides a simple and extensible object preservation and recovery mechanism.

For remote calls, it is convenient to encode and decode objects, just like implementing object direct transmission.

You can persist objects to media, just as you implement direct object storage.

Allows objects to customize the format of external storage.

The role of serialVersionUID

It is mainly used to verify version consistency. Each class has such an ID, which will be written into the stream together during serialization, so it will be compared with the serialVersionUID value of the current class during deserialization. If the two are the same, it means that the version is consistent, and serialization can succeed. If they are different, serialization fails.

private static final long serialVersionUID = 1234567890L; parent serialization

If a subclass implements the Serializable interface but the parent class does not, then when serializing the subclass, the property state of the subclass is written and the property state of the parent class is not written. So if you want the parent class attribute state to participate in serialization as well, make it implement the Serializable interface as well.

In addition, if the parent class does not implement the Serializable interface then deserializing the resulting object calls the constructor of the parent class again to complete initialization of the parent class. So the initial value of the parent class attribute is generally the default value of the type.

Externalizable interface function

The Externalizable interface mainly provides a custom serialization mode, inherits the Serializable interface, and provides two methods, writeExternal and readExternal, to control serialization and deserialization of content.

serialization control

All fields are serialized by default

Static fields are not serialized

transient keyword modifier fields are not serialized

Fields that a class needs to serialize can be declared through an ObjectStreamField array

At this point, I believe that everyone has a deeper understanding of "Java serialization knowledge points," may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report