Java Networking and AWT

Questions about Java network programming (sockets, InetAddress) and AWT event handling

7 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following statements is/are valid to create a server socket?

  1. ServerSocket s1 = new ServerSocket(25);
  2. ServerSocket s1 = new ServerSocket(8000);
  3. ServerSocket s1 = new ServerSocket(80);
  4. Both (1) and (3)
  5. ServerSocket s1 = new ServerSocket(21);
Question 2 Multiple Choice (Single Answer)

Which of the following exceptions is thrown by the Java compiler when we try to create a server socket on a port which is busy?

  1. Java.net.BindException
  2. Java.net.BusyPortException
  3. Java.net.UnknownHostException
  4. Java.net.PortNotFoundException
  5. Java.net.PortBusyException
Question 3 Multiple Choice (Single Answer)

In Java network programming, which of the following statements is/are used by the client to request a connection to the server?

  1. Socket s1 = new Socket(“130.12.23.24”,8000);
  2. Socket s1 = new Socket(130.12.23.24,8000);
  3. Socket s1 = new Socket(“darke.armstrong.edu”,8000);
  4. Only 1 and 3
  5. 1, 2 and 3
Question 4 Multiple Choice (Single Answer)

In Java network programming, which of the following methods is/are defined in “InetAddress” class?

  1. getHostName();
  2. getHostAddress();
  3. getHostType();
  4. Both (1) and (3)
  5. Both (1) and (2)
Question 5 Multiple Choice (Single Answer)

In Java networking, when a client socket cannot find a server, which of the following exceptions is thrown?

  1. Java.net.BindException
  2. Java.net.UnknownHostException
  3. Java.net.ServerNotFoundException
  4. Java.net.UnknownServerException
  5. Java.net.NoServerFoundException
Question 6 Multiple Choice (Single Answer)

Which of the following methods cannot be invoked from the instance of frame class in AWT?

public class If2
{
 static boolean b1, b2;
 public static void main(String [] args)
 {
 int x = 0;
 if ( !b1 ) /* Line 7 */
 {
 if ( !b2 ) /* Line 9 */ { b1 = true;
 x++; if ( 5 > 6 )
 {
 x++;
 }
 if ( !b1 ) x = x + 10;
 else if ( b2 = true ) /* Line 19 */ x = x + 100;
 else if ( b1 | b2 ) /* Line 21 */ x = x + 1000;
 }
 } System.out.println(x);
 }
 }

  1. setLocation(int, int)
  2. setVisible(Boolean)
  3. setSize(int, int)
  4. setDefaultCloseOperation(int)
  5. Pack()
Question 7 Multiple Choice (Single Answer)

Which of the following event types is invalid in Java?

class Equals
 {
 public static
void main(String [] args)
 {
 int x = 100;
 double y = 100.1;
 boolean b = (x = y);
 /* Line 7 */ System.out.println(b);
 }
}

  1. FocusEvent
  2. ComponentEvent
  3. AdjustmentEvent
  4. WindowEvent
  5. ExceptionEvent