Select an option to see the answer and solution.
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.
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.
Select an option to see the answer and solution.
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.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
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.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
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.
Select an option to see the answer and solution.
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.
Select an option to see the answer and solution.
Select an option to see the answer and solution.
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.
Select an option to see the answer and solution.
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.
Select an option to see the answer and solution.