views:

259

answers:

3

What is the difference between serialization and synchronization in java? I need an explanation or a tutorial.

+5  A: 

Synchronization refers to multi-threading. A synchronized block of code can only be executed by one thread at a time.

Serialization refers to converting objects to bitstreams either for storage or transmission. The act of serialization encodes the data according to specific rules. This bitstream can then be deserialized later or on a remote system that receives it. For serialization to work the class definition must match (i.e. you need to be using the same version of the class or one that is guaranteed to be compatible) and the class must implement the Serializable interface.

More on serialization.

More on synchronization

Kris
+1; just a couple of additional remarks. First of all, the term serialization is also sometimes used in the context of handling requests *in sequence* rather than simultaneously. Other than that, I would say Java objects are serialized to bytestreams rather than bitstreams. AFAIK, output is always byte-aligned.
Wilfred Springer
A: 

serialization is taking an object and dumping it to something that is outside the program's scope (e.g. a string or an xml file)

synchronization is a concept of having different running threads in sync with each other so that they do not, for example, use a shared resource at the same time.

As far as I know these terms have very little in common (unless you have a question about how to synchronize two threads that need on serialize the same object)

Nir Levy
A: 

Synchronization is a concurrency issue, e.g. how do you coordinate access to an object from multiple threads.

Here an arrow represents access.

                            s
 [thread1] ---------------> y
                            n [shared object]
 [thread2] ---------------> c
                            h

Serialization is the conversion of data structures and objects into a sequence of bits that you can store/transmit and then convert back to data structures and objects.

Here an arrow represents conversion.

            deserialization
           <---------------
  [object]                  [binary]
           --------------->
            serialization

This is most useful when the deserialization happens at another place and/or time.

polygenelubricants