72.
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);
      ois.close();
      System.out.println(ois.available());		    	
  }
  catch (Exception e)
        {
            System.out.print("deserialization");
      System.exit(0);
  }
    }
}

75.
What will be the output of the following Java program?
import java.io.FileOutputStream;  
public class FileOutputStreamExample
{  
    public static void main(String args[])
    {    
           try
           {    
             FileOutputStream fout=new FileOutputStream("D:\\example.txt");    
             String s="Welcome to India.";    
             byte b[]=s.getBytes();//converting string into byte array    
             fout.write(b);    
             fout.close();    
             System.out.println("Success");    
            }  catch(Exception e){System.out.println(e);}    
      }    
}

76.
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  
        {
            Myclass object2;
      FileInputStream fis = new FileInputStream("serial");
      ObjectInputStream ois = new ObjectInputStream(fis);
            object2 = (Myclass)ois.readObject();
            ois.close();
      System.out.println(object2);		    	
  }
  catch (Exception e) 
        {
            System.out.print("deserialization" + e);
      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;
}
}

80.
What will be the output of the following Java code?
import java.net.*;
class networking 
{
    public static void main(String[] args) throws MalformedURLException 
    {
        URL obj = new URL("https://www.example.com/javamcq");
        System.out.print(obj.getProtocol());
    }
}

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.