3 Replies Latest reply on May 28, 2010 4:34 AM by EJP

    How serialization works internally

    843790
      Hi,

      I want to know how is serialization achieved? Is that the JVM that does the serialization? If yes how it does that.

      Thanks
      Neha
        • 1. Re: How serialization works internally
          EJP
          It is mostly done by ObjectOutputStream with a tiny little assistance from some secret classes and eventually some JNI, just to create the object without invoking a constructor.
          • 2. Re: How serialization works internally
            843790
            As Serializable is a marker interface, i have read some somewhere that

            "Market interfaces are just used to tell the the JVM that, just do specific things which is jvm specific for the objects which implements those interfaces. Means all the objects which implements marker interface, only jvm is responsible to do the specific functionality."

            So wanted to understand what is the role of JVM in doing serialization or any other thing say cloning that implements marker interfaces? Also if i create a marker interface, is there some thing we need to do explicitly to tell JVM that the interface is a marker interface?

            And
            • 3. Re: How serialization works internally
              EJP
              i have read some somewhere that

              "Market interfaces are just used to tell the the JVM that, just do specific things which is jvm specific for the objects which implements those interfaces. Means all the objects which implements marker interface, only jvm is responsible to do the specific functionality."
              God help us. That is 99% drivel. 'Specific things which is JVM-specific' has practically no meaning whatsoever. 'Only JVM is responsible to do the specific functionality' is just plain wrong, as obviously you can create your own marker interface decades after the JVM is written.

              Don't rely on 'I have read somewhere.' Use the official Java documentation.

              The role of the JVM in all this is to implement if (x instanceof Serializable) correctly. If you have your own marker interface, its role is to implement if (x instanceof MyMarkerInterface) correctly. That's it.

              Edit: I found where you got that. The entire page is drivel. Not one of the three answers is correct. Not one of those authors has the slightest idea what they are talking about. Don't rely on websites like this. Use the official documentation and specifications.