search

Home  >  Q&A  >  body text

java 实体类序列化

一直不是很懂很多写实体类实现序列化 是干嘛 有什么好处?

迷茫迷茫2847 days ago564

reply all(2)I'll reply

  • PHPz

    PHPz2017-04-18 09:16:06

    When a class is written, it just lies in a text file with the .java suffix. Simply put, it is on the hard disk.
    The written Java file is compiled into a .class file and then loaded and run by the Java virtual machine.
    When running, classes are represented in memory. Instances generated by the new keyword also exist in memory.
    Instances of classes have a certain storage format in memory (you can refer to the Java virtual machine specification, object storage format), which is different from the storage format when it is lying on the hard disk before it is run.

    Serialization is to store an instance in memory on the hard disk in another storage method (refer to "Core Java"). In other words, it is called Persistence.

    In this way, as long as others get the data of this serialized instance, they can restore the current state of the object through deserialization.

    There are many serialization application scenarios, such as rmi and rpc. You can refer to relevant information.

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 09:16:06

    1.rmi (remote method invocation). When delivering messages to remote objects, object serialization is required to pass parameters and return values.
    2. Implement lightweight persistence by writing the serialized object to disk and then reading it out when the program is run again.

    reply
    0
  • Cancelreply