Serialization and Networking Mcqs

Our collections of Multiple choice questions and answers focuses on study of ” Serialization and Networking “. These questions are chosen from a collection of most authoritative and best reference books on Java. Our aim is to prepare an individual for competitive exams like NTS, GAT, ECAT, University and College entrance exams and various tests and job interviews. One should practice our Mcqs to assimilate Java Serialization and Networking comprehensively.

1.
What is deserialization?

Turning object in memory into stream of bytes

Turning stream of bytes into an object in memory

Turning object in memory into stream of bits

Turning stream of bits into an object in memory

4.
If member does not implement serialization, which exception would be thrown?

RuntimeException

SerializableException

NotSerializableException

UnSerializedException

5.
Which of the following methods is used to avoid serialization of new class whose super class already implements Serialization?

WriteObject()

ReadWriteObject()

WriteReadObject()

UnSerializaedObject()

10.
Which of these is a method of ObjectInput interface used to deserialize an object from a stream?

Int read()

Void close()

Object readObject()

Object WriteObject()

12.
What is the output of this program?

      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);
     }
        }
    }  

5

Void

Serialization

Deserialization

13.
What is the output of this program?<br/>

        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;
 }
    }

-7

Hello

2.1E10

Deserialization

error: You are not allowed to do so.....
0Shares
0
Scroll to Top