What is java reflection and serialization? When is serialization required?

What is reflection?

The so-called reflection, , obtains the various components of a class 是java在运行时进行自我观察的能力through four methods.class、constructor、field、method

In the Java runtime environment, 对任意一个类,可以知道类有哪些属性和方法. This function of dynamically obtaining class information and dynamically calling methods of objects comes from the reflection mechanism .

What is java serialization? When is serialization required?

序列化就是一种用来处理对象流的机制. Stream the content of the object and transfer the streamed object between networks.

Serialization is implemented serializable接口. There is no method that needs to be implemented in this interface. implement Serializable只是为了标注该对象是可被序列化的An output stream (FileOutputStream) is used 构造一个ObjectOutputStream对象, followed by an ObjectOutputStream object writeObejct(Object object)方法就可以将参数的obj对象到磁盘, and the input stream is used when recovery is required.

Serialization is the process of converting an object into an easily transportable format.

For example, an object can be serialized and then transferred between a client and server over the Internet via HTTP. On the other end, deserialization will construct objects from the stream hub.

一般程序在运行时,产生对象,这些对象随着程序的停止而消失,但我们想将某些对象保存下来,这时,我们就可以通过序列化将对象保存在磁盘, obtained through deserialization when needed.

The main purpose of object serialization is to transfer and save objects, and preserve the integrity and transferability of objects.

For example, when transferring over a network or saving an object as a local file, serialization needs to be used.

Guess you like

Origin blog.csdn.net/m0_48170265/article/details/130075539