A brief talk on serialization __java of Java Serializable series

Source: Internet
Author: User
The Java serialization technology that serializes Java objects into binaries is one of the more important technical points in the Java family of technologies, and in most cases developers only need to understand that the serialized class needs to implement the Serializable interface, using ObjectInputStream and O Bjectoutputstream to read and write objects. However, in some cases, it is not enough to know these, the article lists some of the real situation I encountered, they are related to Java serialization, through the analysis of the reasons for the situation, so that readers can easily remember the Java serialization of some high-level understanding.
"serialized serialversionuid Problem"
In Java serialization and deserialization, whether the virtual machine allows deserialization, not only depends on the class path and functional code is consistent, a very important point is the two class serialization ID is consistent (is the private static final long Serialversionuid = 1L), if the serialversionuid is different, you will get a java.io.InvalidClassException, an output example: java.io.InvalidClassException: Serialization_deserialization.person; Local class Incompatible:stream Classdesc serialversionuid = 1, local class Serialversionuid = 100
Look at the following code:
[Java]  View plain copy package wen.hui.test.serializable;      import  java.io.serializable;     /**   * serializable test    *   *   @author  whwang   * 2011-12-1  pm 09:50:07   */   public  class a implements serializable {          private  static final long serialVersionUID = 2L;           public a ()  {          }          public void print ()  {            system.err.println ("test serializable");       }          public static void main (String[] args)  throws  exception {          }  }   [Java]View plain copy package wen.hui.test.serializable;   Import Java.io.FileInputStream;   Import Java.io.FileOutputStream;   Import Java.io.ObjectInputStream;      Import Java.io.ObjectOutputStream; /** * * @author Whwang * 2011-12-1 pm 09:54:36/public class Test1 {public static void main (string[)           args) throws Exception {//write object String fileName = "obj"; Towrite (FileName);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.