Vidyalelo
Java Programming · all questions

Java Serialization and Networking
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

113

Questions

3/6

Page

Pick an option on a question to see the right answer and solution.

What is serialization?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

How many ports of TCP/IP are reserved for specific protocols?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which of these methods is used to know host of an URL?

Select an option to see the answer and solution.

Which of these interface extends DataOutput interface?

Select an option to see the answer and solution.

Which of these is a standard for communicating multimedia content over email?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What type of members are not serialized?

Select an option to see the answer and solution.

Which of these interface extends DataInput interface?

Select an option to see the answer and solution.

Which of these class is used to access actual bits or content information of a URL?

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.net.*;
public class networking 
{
    public static void main(String[] args) throws UnknownHostException 
    {
        InetAddress obj1 = InetAddress.getByName("cisco.com");
        InetAddress obj2 = InetAddress.getByName("example.com");
        boolean x = obj1.equals(obj2); 
        System.out.print(x);
    }
}

Select an option to see the answer and solution.

Which of these method of DatagramPacket class is used to find the destination address?

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.net.*;
class networking 
{
    public static void main(String[] args) throws UnknownHostException 
    {
        InetAddress obj1 = InetAddress.getByName("example.com");
        InetAddress obj2 = InetAddress.getByName("example.com");
        boolean x = obj1.equals(obj2); 
        System.out.print(x);
    }
}

Select an option to see the answer and solution.

Which of these method of DatagramPacket is used to find the port number?

Select an option to see the answer and solution.

Which of these variables stores the number of hits that are successfully served out of cache?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What is deserialization?

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.net.*;
class networking
{
    public static void main(String[] args) throws Exception 
    {
        URL obj = new URL("https://www.example.com/javamcq");
        URLConnection obj1 = obj.openConnection();
        int len = obj1.getContentLength();
        System.out.print(len);
    }
}

Note: Host URL is having length of content 127.

Select an option to see the answer and solution.

Which of these method is called when http daemon is acting like a normal web server?

Select an option to see the answer and solution.