Site icon DataFlair

Quiz on Socket Programming in Java

quiz on socket programming in java

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Dive into the world of socket programming in Java and test your mettle with this interactive quiz! Socket programming opens doors for your Java applications to communicate and exchange data across networks.

This engaging quiz delves into core concepts critical to establishing socket connections in Java. Are you a seasoned developer looking to refresh your knowledge, or a curious beginner eager to embark on your socket programming journey?

This quiz caters to both ends of the spectrum, offering a valuable tool to assess your understanding and pinpoint areas where you might require further exploration.

By tackling these questions, you’ll gain valuable insights into the fundamentals of creating sockets, binding them to ports, initiating connections, and effectively managing data flow. So, sharpen your skills, test your knowledge, and embark on a rewarding learning experience with this socket programming quiz!

Time limit: 0

Quiz Summary

0 of 15 Questions completed

Questions:

Information

You have already completed the quiz before. Hence you can not start it again.

Quiz is loading…

You must sign in or sign up to start the quiz.

You must first complete the following:

Results

Quiz complete. Results are being recorded.

Results

0 of 15 Questions answered correctly

Your time:

Time has elapsed

You have reached 0 of 0 point(s), (0)

Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)

Categories

  1. Not categorized 0%
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  1. Current
  2. Review / Skip
  3. Answered
  4. Correct
  5. Incorrect
  1. Question 1 of 15
    1. Question

    Which of the following is the correct syntax for socket connection ?

    Correct
    Incorrect
  2. Question 2 of 15
    2. Question

    class Program {

    public static void main ( String args [ ] )

    {

    Socket socket;

    DataInputStream input;

    DataOutputStream output;

    input = DataInputStream (System.in);

    Program {

    Socket socket = new Socket(“127.0.0.1”, 5000);

    System.out.println(“Established”);

    }

    Program p = new Program();

    }

    }

    The given program is an example of which type of Socket programming ?

    Correct
    Incorrect
  3. Question 3 of 15
    3. Question

    Which of the following is the correct syntax to accept a socket connection ?

    Correct
    Incorrect
  4. Question 4 of 15
    4. Question

    Which of the following is not used in a socket connection ?

    Correct
    Incorrect
  5. Question 5 of 15
    5. Question

    class Message {

    public static void main ( String args [ ] )

    {

    String servername = “servername”;

    int port = portnumber;

    Socket client = new Socket(servername,portnumber);

    OutputStream out = client.getOutputStream();

    DataOutputStream stream = new DataOutputStream(out);

     

    stream.write(“Message for client”);

    InputStream in = client.getInputStream();

    DataInputStream input = new DataInputStream(in);

     

    System.out.println(in.ReadUTF()):

    client.close();

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  6. Question 6 of 15
    6. Question

    class Exception {

    public static void main ( String args [ ] )

    {

    void Connection()
        {

    Socket socket = new Socket(5021,”126.4.3.1”);

    System.out.println(“Connection is established”);

    }

    }

    }

    What is the error in the program ?

    Correct
    Incorrect
  7. Question 7 of 15
    7. Question

    Which of the following methods are used to send the data through the data Stream ?

    Correct
    Incorrect
  8. Question 8 of 15
    8. Question

    class Function {

    public void method(String Address, double Port)

    {

    Socket socket = new Socket();

    DataInputStream input = new DataInputStream();

    System.out.println(Address,Port);

    }

    class Main {

    public static void main ( String args [ ] )

    {

    Function f = new Function();

    f.method(“127.1.1.9”,8765);

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  9. Question 9 of 15
    9. Question

    class Example {

    public static void main ( String args [ ] )

    {

        throws IOException {

        Socket socket = new Socket(3278);

    InputStream input = socket.InputStream();

    DataInputStream in = new DataInputStream(input);

    input.close();

    in.close();

    socket.close();

    catch(UnknownHostException exception)

    System.out.println(exception)

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  10. Question 10 of 15
    10. Question

    Which of the following is used to close the socket connection ?

    Correct
    Incorrect
  11. Question 11 of 15
    11. Question

    class SimpleClient {

    public static void main ( String args [ ] )

    {

        throws IOException {

        Socket socket = new Socket(“host”,3278);

    InputStream input = socket.InputStream();

    DataInputStream in = new DataInputStream(input);

    String string = new String(in.ReadUTF());

    System.out.println(string);

    input.close();

    in.close();

    socket.close();

    }

    }

    What is the output of the program ?

    Correct
    Incorrect
  12. Question 12 of 15
    12. Question

    class Main {

    public static void main ( String args [ ] )

    {

    Address host = Address.getLocalHost();

            Socket socket = null;

            ObjectOutputStream out = null;

            ObjectInputStream in = null;

            for(int i=0; i<3;i++){

                socket = new Socket(host.getHostName(), 4357);

                oos = new ObjectOutputStream(socket.getOutputStream());

                System.out.println(“Server request sent”);

                if(i==2)out.writeObject(“exit”);

                else out.writeObject(“”+i);

                in = new ObjectInputStream(socket.getInputStream());

                String message = (String) ois.readObject();

                System.out.println(“Message: ” + message);

          in.close();

                out.close();

            }

        }

    What is the function of the given program ?

    Correct
    Incorrect
  13. Question 13 of 15
    13. Question

     Which of the following classes are used for socket programming in java ?

    Correct
    Incorrect
  14. Question 14 of 15
    14. Question

     class SocketProgramming {

    public static void main ( String args [ ] )

    {

    String servername = “126.9.0.3”;

    int port = 4531;

    Socket client = new Socket(servername,portnumber);

    OutputStream out = client.getOutputStream();

    DataOutputStream stream = new DataOutputStream(out);

    System.out.println(stream.write(“welcome client”);

    InputStream in = client.getInputStream();

    DataInputStream input = new DataInputStream(in);

    System.out.println(in.ReadUTF()):

    client.close();

    }

    }

    What is the error in the program ?

    Correct
    Incorrect
  15. Question 15 of 15
    15. Question

    class Client {

    public static void main ( String args [ ] )

    {

    long port;

    String address;

    public void method ( address , port )

    {

    Socket socket = new Socket( address , port );

    System.out.println(“Connection is established in this “ + address + “ using this “ + port “);

    }

    method(“130.0.0.2”,4329);

    }

    }

    What is the output of the program ?

    Correct
    Incorrect

Summary:

So how did you fare on the Java socket programming quiz? This quiz covered the essential syntax for creating socket connections, including specifying IP addresses and port numbers.

By attempting the quiz, you’ve gained valuable insights into your grasp of this fundamental aspect of socket programming. Remember, effective learning is an ongoing process. Explore additional resources like online tutorials, practice problems, and online communities to solidify your understanding and delve deeper into the exciting world of Java socket programming.

Exit mobile version