search
HomeJavajavaTutorialWhy should we implement Serializable serialization interface in java?

Why should we implement Serializable serialization interface in java?

Nov 30, 2019 pm 05:03 PM
javaaccomplishSerializationinterface

Why should we implement Serializable serialization interface in java?

We learned ObjectInputStream and ObjectOutputStream when we were learning JavaSE. At that time, we felt that as long as an object was to be written to a file, it must be implemented. Serializable interface. In fact, there is absolutely no problem in understanding it this way.

1. Introduction to the problem

Why should we implement the serialization interface in Java? Let’s take a look at the picture below:

Why should we implement Serializable serialization interface in java?

In the Java program, a data is written to the disk. If the data is an ordinary string, then there is no problem, all machines can To recognize a string normally, even if it needs to be converted into the corresponding bytes, the computer also knows how to convert the string into the corresponding bytes (code table), but if it is a Java object, it will be troublesome. The disk does not know what you passed. It is a Java object. In other words, the disk does not know what format to convert the Java object into the corresponding bytes.

Related video tutorial sharing: java learning

We know that a Java object is essentially a class bytecode, and the disk does not know how to write this bytecode How to write to the disk, so you need to "identify" it and tell the disk: "I am a Java object, you want to write it to the disk in this way", but "write it to the disk in this way" disk". Therefore, implementing the Serializable interface just identifies "I am a Java object"

If you understand the above text, it will not be difficult to understand the following picture:

Why should we implement Serializable serialization interface in java?

2. Deepen understanding

Java provides an object serialization mechanism. An object can be represented by a byte sequence that contains information such as the object's data, the object's type, and the attributes stored in the object. After the byte sequence is written to the file, it is equivalent to persisting the information of an object in the file.

On the contrary, the byte sequence can also be read back from the file, reconstruct the object, and deserialize it. The object's data, the object's type, and the data information stored in the object can all be used to create objects in memory. Look at the picture to understand serialization:

Why should we implement Serializable serialization interface in java?

Recommended related articles and tutorials: java entry program

The above is the detailed content of Why should we implement Serializable serialization interface in java?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools