adplus-dvertising

Welcome to the Serialization and Networking MCQs Page

Dive deep into the fascinating world of Serialization and Networking with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Serialization and Networking, a crucial aspect of Java Programming. In this section, you will encounter a diverse range of MCQs that cover various aspects of Serialization and Networking, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Java Programming.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Serialization and Networking. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Java Programming.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Serialization and Networking. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Serialization and Networking MCQs | Page 8 of 9

Q71.
Which of these is a return type of getAddress() method of DatagramPacket class?
Discuss
Answer: (c).InetAddress
Q72.
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.
Discuss
Answer: (a).getSocketAddress()
Q73.
What is the output of this 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();
	    }
	}
    }
Discuss
Answer: (d).None of the mentioned
Q74.
What is the output of this 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 
            {
	        float 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);
	    }
        }
    }
Discuss
Answer: (b).3.5
Q75.
What is the output of this 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);
	    }
        }
    }

a.

1

b.

2

c.

3

d.

0

Discuss
Answer: (d).0
Q76.
What is the output of this 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);
	        System.out.println(ois.available());		    	
	    }
	    catch (Exception e) 
            {
                System.out.print("deserialization");
	        System.exit(0);
	    }
        }
    }

a.

1

b.

2

c.

3

d.

4

Discuss
Answer: (d).4
Q77.
What will be printed to the output and written to the file, in the below program?
import java.io.FileOutputStream;  
public class FileOutputStreamExample
{  
    public static void main(String args[])
    {    
           try
           {    
             FileOutputStream fout=new FileOutputStream("D:\\compscibits.txt");    
             String s="Welcome to Compscibits";    
             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: (a).“Success” to the output and “Welcome to Compscibits ” to the file
Q78.
What is the output of this program?
import java.io.*;  
import java.net.*;  
public class URLDemo 
{  
    public static void main(String[] args) 
    {  
        try 
        {  
            URL url=new URL("https://www.compscibits.com/mcq-questions/Java-Programming");  
            System.out.println("Protocol: "+url.getProtocol());  
            System.out.println("Host Name: "+url.getHost());  
            System.out.println("Port Number: "+url.getPort());   
        } catch(Exception e){System.out.println(e);}  
    }  
}
Discuss
Answer: (d).all of the mentioned
Q79.
What is the output of this program?
    import java.net.*;
    class networking 
    {
        public static void main(String[] args) throws UnknownHostException 
        {
            InetAddress obj1 = InetAddress.getByName("cisco.com");
            System.out.print(obj1.getHostName());
        }
    }
Discuss
Answer: (b).cisco.com
Q80.
What is the output of this program?
    import java.net.*;
    class networking
    {
        public static void main(String[] args) throws MalformedURLException 
        {
            URL obj = new URL("https://www.compscibits.com/mcq-questions/Java-Programming");
            System.out.print(obj.getHost());
        }
    }
Discuss
Answer: (c).www.compscibits.com
Page 8 of 9

Suggested Topics

Are you eager to expand your knowledge beyond Java Programming? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!