Home > Java > javaTutorial > body text

Detailed introduction to Java object serialization

黄舟
Release: 2017-09-16 10:56:49
Original
1291 people have browsed it

java provides two methods of object persistence: serialization and external serialization

(1) Serialization Serialization

Serialization is a method of converting an object into a string of bytes Describes a process for solving problems caused by reading and writing object streams.

All classes to be serialized must implement the serializable interface

(2) External serialization (externalizable)

To implement external serialization, you need to implement readExternal(ObjectInput in) and writeExternal(ObjectOutput out) method.

Serialization features:

1. If a class can be serialized, its subclasses can also be serialized.

2. Since variables or methods modified with static represent members of the class, and variables modified with the transient keyword represent temporary data of the object, data members declared in these two types cannot be serialized.

When to use serialization?

1. The object needs to be sent over the network or the state of the object needs to be persisted to the database or file

2. Serialization can achieve deep copying.

The above is the detailed content of Detailed introduction to Java object serialization. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template