ExamVeda
Login
Home
71
Which of these is method of ObjectOutput interface used to write the object to input or output stream as required?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
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);
  }
    }
}
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
73
Which of these methods of httpd class is used to read data from the stream?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
74
Which of these package contains classes and interfaces for networking?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
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);}    
      }    
}
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
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;
}
}
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
77
If member does not implement serialization, which exception would be thrown?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
78
How many bits are in a single IP address?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
79
Which of these transfer protocol must be used so that URL can be accessed by URLConnection class object?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
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());
    }
}
Discuss
Answer & Solution
Answer: Option B
Solution:
The correct answer is Option B: https.
Let's break down why:
The code uses the java.net.URL class, which is designed to work with URLs (Uniform Resource Locators).
A URL is essentially an address for a resource on the internet, like a webpage.
The line URL obj = new URL("https://www.example.com/javamcq"); creates a new URL object named 'obj'. This object represents the URL "https://www.example.com/javamcq".
The obj.getProtocol() method is called. This method specifically extracts the protocol part of the URL.
The protocol is the first part of a URL that indicates how the data will be transferred. Common protocols are "http" and "https".
In the given URL "https://www.example.com/javamcq", the protocol is "https".
Therefore, obj.getProtocol() will return "https", which is then printed to the console using System.out.print().