71. Which of these is method of ObjectOutput interface used to write the object to input or output stream as required?
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);
}
}
}
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);
}
}
}
73. Which of these methods of httpd class is used to read data from the stream?
74. Which of these package contains classes and interfaces for networking?
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);}
}
}
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;
}
}
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;
}
}
77. If member does not implement serialization, which exception would be thrown?
78. How many bits are in a single IP address?
79. Which of these transfer protocol must be used so that URL can be accessed by URLConnection class object?
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());
}
}
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.