enfrptes

sendassignment@tutorspoint.com

Serialization Homework Help

What is Serialization in Java?

It is the concept of transferring the objects (data) of classes from the RAM to any other location outside the RAM. To get Serialization Homework Help contact tutorspoint.com

Example:

  1. Transferring the state of an object from RAM to hard disk.
  2. Transferring the state of an object from RAM to a storage device in another system with the help of a network.

We can’t transfer objects of all classes from RAM to other locations outside RAM.

  1. There is an interface by name serializable. It is a zero-body interface i.e. it has no function definitions.
  2. The object of classes that implement serializable.  Interface only, is eligible for serialization.
  3. Object output stream class helps us in transferring the objects of classes from our program (i.e. RAM) to other locations.
  4. Similarly object input stream class helps us in transferring the objects of classes from other locations to our program.
  5. Object output stream class has a method by name write object (). It takes, the object of a class that implements a serializable interface, as an argument, or in other words, it takes the serializable interface reference which
  6. points to the object of a class that implements this interface, as an argument.
  7. The object of the object output stream class on which the write object () method is called holds the address of the destination location to which the object is to be transferred.

Example:

File output stream     for = new file output stream (“file1.obj”);

Object output stream    oos = new object output stream (FOS);

Oos. write object (serializable   s)

Aa1 = new A ();

Explanation:

In the above example, the object of the file output stream contains the address of the file which is present in the hard disk. Fos is made available to the object of the object output stream class oos. Now on oos, we call the write object () method. In this way address of the destination is made available to write the object () method in which the object is to be written. We can’t transfer objects of all classes from RAM to other locations outside RAM.