Home > Java Programming > Quizzes > Java Basics Practice Test: Serialization & Networking
Java Basics Practice Test: Serialization & Networking
Fast practice, instant feedback. Timer auto-submits when time’s up.
Avg score: 0% Most missed: “Which of these is a process of writing the state of an object to a byte stream?”
Quiz on networking basics, server, sockets and httpd class, serialization, deserialization, url class, networking datagrams, htttpresponse and urlconnection class. Java serialization is the process of converting an object into a stream of bytes that can be saved to a file or transmitted over a network. It is used to store and transmit data in a format that can be easily read and written by different Java applications. Java networking is the process of using Java to create applications that can communicate over a network. It allows Java applications to exchange data with other applications... Show more
Java Basics Practice Test: Serialization & Networking
Time left 00:00
25 Questions

1. Which of these class must be used to send a datagram packets over a connection?
2. 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;
}
}
3. Which of these methods of DatagramPacket is used to find the length of byte array?
4. 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.fatskills.com/javamcq");
URLConnection obj1 = obj.openConnection();
System.out.print(obj1.getContentType());
}
}

Note: Host URL is written in html and simple text.
5. Which of these is a full form of DNS?
6. What will be the output of the following Java program?
import java.io.*;
class Chararrayinput
{
public static void main(String[] args)
{
String obj = "abcdefgh";
int length = obj.length();
char c[] = new char[length];
obj.getChars(0, length, c, 0);
CharArrayReader input1 = new CharArrayReader(c);
CharArrayReader input2 = new CharArrayReader(c, 1, 4);
int i;
int j;
try
{
while ((i = input1.read()) == (j = input2.read()))
{
System.out.print((char)i);
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
7. Which of these methods is used to know host of an URL?
8. Which of these is a wrapper around everything associated with a reply from an http server?
9. Which of the following methods is used to avoid serialization of new class whose super class already implements Serialization?
10. 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);
}
}
}
11. Which of these is a full form of DNS?
12. What is serialization?
13. 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("fatskills.com");
boolean x = obj1.equals(obj2);
System.out.print(x);
}
}
14. Which of these class is necessary to implement datagrams?
15. Which of these transfer protocol must be used so that URL can be accessed by URLConnection class object?
16. How many bits are in a single IP address?
17. Which of these is a method of ObjectInput interface used to deserialize an object from a stream?
18. Which of these class extend InputStream class?
19. Which of these methods is used to make raw MIME formatted string?
20. Which of these is a standard for communicating multimedia content over email?
21. Which of these is method of ObjectOutput interface used to write the object to input or output stream as required?
22. Which of these is an instance variable of class httpd?
23. Which of these is a method of ObjectOutput interface used to finalize the output state so that any buffers are cleared?
24. Which API gets the SocketAddress (usually IP address + port number) of the remote host that this packet is being sent to or is coming from.
25. 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;
}
}