Java Networking and AWT
Questions about Java network programming (sockets, InetAddress) and AWT event handling
Questions
Which of the following statements is/are valid to create a server socket?
- ServerSocket s1 = new ServerSocket(25);
- ServerSocket s1 = new ServerSocket(8000);
- ServerSocket s1 = new ServerSocket(80);
- Both (1) and (3)
- ServerSocket s1 = new ServerSocket(21);
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?
- Java.net.BindException
- Java.net.BusyPortException
- Java.net.UnknownHostException
- Java.net.PortNotFoundException
- Java.net.PortBusyException
In Java network programming, which of the following statements is/are used by the client to request a connection to the server?
- Socket s1 = new Socket(“130.12.23.24”,8000);
- Socket s1 = new Socket(130.12.23.24,8000);
- Socket s1 = new Socket(“darke.armstrong.edu”,8000);
- Only 1 and 3
- 1, 2 and 3
In Java network programming, which of the following methods is/are defined in “InetAddress” class?
- getHostName();
- getHostAddress();
- getHostType();
- Both (1) and (3)
- Both (1) and (2)
In Java networking, when a client socket cannot find a server, which of the following exceptions is thrown?
- Java.net.BindException
- Java.net.UnknownHostException
- Java.net.ServerNotFoundException
- Java.net.UnknownServerException
- Java.net.NoServerFoundException
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);
}
}
- setLocation(int, int)
- setVisible(Boolean)
- setSize(int, int)
- setDefaultCloseOperation(int)
- Pack()
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);
}
}
- FocusEvent
- ComponentEvent
- AdjustmentEvent
- WindowEvent
- ExceptionEvent