41.
What is serialization?

42.
What will be the output of the following Java code?
import java.io.*;
class streams 
{
    public static void main(String[] args)
    {
        try 
        {
      FileOutputStream fos = new FileOutputStream("serial");
      ObjectOutputStream oos = new ObjectOutputStream(fos);
      oos.writeInt(5);
      oos.flush();
      oos.close();
  }
  catch(Exception e)
        {
      System.out.println("Serialization" + e);
            System.exit(0);
        }
  try
        {
      int z;
      FileInputStream fis = new FileInputStream("serial");
      ObjectInputStream ois = new ObjectInputStream(fis);
      z = ois.readInt();
      ois.close();
      System.out.println(x);		    	
  }
  catch (Exception e) 
        {
            System.out.print("deserialization");
      System.exit(0);
  }
    }
}

44.
What will be the output of the following Java program?
import java.io.*;
class serialization 
{
    public static void main(String[] args) 
    {
        try 
        {
            Myclass object1 = new Myclass("Hello", -7, 2.1e10);
      FileOutputStream fos = new FileOutputStream("serial");
      ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(object1);
            oos.flush();
            oos.close();
  }
  catch(Exception e) 
        {
      System.out.println("Serialization" + e);
            System.exit(0);
        }
  try
        {
      int x;
      FileInputStream fis = new FileInputStream("serial");
      ObjectInputStream ois = new ObjectInputStream(fis);
            x = ois.readInt();
            ois.close();
      System.out.println(x);		    	
  }
  catch (Exception e)
        {
            System.out.print("deserialization");
      System.exit(0);
  }
    }
}
class Myclass implements Serializable
{
String s;
int i;
double d;
    Myclass(String s, int i, double d)
    {
  this.d = d;
  this.i = i;
  this.s = s;
}
}

48.
What will be the output of the following Java code?
import java.io.*;
class serialization
{
    public static void main(String[] args)
    {
        try
        {
      Myclass object1 = new Myclass("Hello", -7, 2.1e10);
      FileOutputStream fos = new FileOutputStream("serial");
      ObjectOutputStream oos = new ObjectOutputStream(fos);
      oos.writeObject(object1);
      oos.flush();
      oos.close();
  }
  catch(Exception e)
        {
      System.out.println("Serialization" + e);
            System.exit(0);
        }
  try
        {
      int x;
      FileInputStream fis = new FileInputStream("serial");
      ObjectInputStream ois = new ObjectInputStream(fis);
      x = ois.readInt();
      ois.close();
      System.out.println(x);		    	
  }
  catch (Exception e)
        {
            System.out.print("deserialization");
      System.exit(0);
  }
    }
}
class Myclass implements Serializable
{
String s;
int i;
double d;
Myclass(String s, int i, double d)
    {
  this.d = d;
  this.i = i;
  this.s = s;
}
}

Read More Section(Java Serialization and Networking)

Each Section contains maximum 100 MCQs question on Java Serialization and Networking. To get more questions visit other sections.