0% found this document useful (0 votes)
16 views

AJP 4 chapter

Uploaded by

vinantymhatre02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

AJP 4 chapter

Uploaded by

vinantymhatre02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1) Once you make a connection to a remote server, you can use _____________

to inspect the properties of the remote object before actually transporting it locally.
a)URL
b)URLConnection
c)URL.Connection
d)None of these

2) We can create a URLConnection using the ___________ method of a URL object


and examine the document’s properties and content:
a)openConnection( )
b)URLConnection()
c)both a and b
d)None of these

3) The _____ class is used to encapsulate both the numerical IP address and the
domain name for that address.
a)IPAddress
b)MACAddress
c) InetAddress
d)None of the above

4) netAddress was specified by which type of IP version?


a) IPv4
b) IPv6
c) Both 1 & 2
d) None of the above

5) IPv6 uses a how many bit value to represent an address?a)32


b)64
c)16
d)128

6) IPv4 uses a how many bit value to represent an address?


a)32
b)128
c)64
d)16

7) InetAddress can handle _____ IP addresses.


a)IPv4
b)IPv6
c)Both 1 & 2
d)None of the above

8) To create an InetAddress object you have to use one of the available _____
a)Interfaces
b)Classes
c)Factory Methods
d)All of the above
9) Which of the following is a correct factory method to create an object in an
InetAddress?
a)getLocalHost()
b)getByName(String hostName)
c)getAllByName(String hostName)
d)All of the above

10) The _____ method returns the InetAddress object that represents the local host.
a)getByName(String hostName)
b)getLocalHost()
c)getAllByName(String hostName)
d)None of the above

11) The _______ method returns an InetAddress for a host name passed to it.
a)getByName(String hostName)
b)getLocalHost()
c)getAllByName(String hostName)
d)None of the above

12) The _______ factory method returns an array of InetAddresses that represent all
of the addresses that a particular name resolves to.
a)getByName(String hostName)b)getLocalHost()
c)getAllByName(String hostName)
d)None of the above

13) The factory method ______ which takes an IP address and returns an InetAddress
object.
a)getByName(String hostName)
b)getLocalHost()
c)getAllByName(String hostName)
d)getByAddress()

14) Which of the following Instance Method returns true if this object has the same
Internet address as other?
a)boolean isMulticastAddress()
b)boolean equals(Object other)
c)String toString()
d)byte[] getAddress()

15) Which of the following Instance Method returns a byte array that represents the
object’s Internet address in network byte order?
a)byte[] getAddress()
b)String getHostName()
c)String toString()
d)boolean isMulticastAddress()
16) Which of the following Instance Method returns a string that represents the host
address associated with the InetAddress object?
a)String toString()
b)boolean equals(Object other)
c)String getHostAddress()
d)None of the above

17) Which of the following Instance Method returns a string that represents the host
name associated with the InetAddress object?
a)String getHostAddress()
b)String getByName()
c)String getHostName()
d)String toString()

18) Which of the folowing Instance Method Returns true if this Internet address is a
multicast address. Otherwise, it returns false?
a)boolean equals(Object other)
b)boolean isMulticastAddress()
c)boolean isMultiCastAddress()
d)boolean MulticastAddress()

19) Which of the following Instance Method returns a string that lists the host name
and the IP address for convenience?
a)String getHostAddress()
b)String getByName()
c)String getHostName()
d)String toString()

20) ______ sockets are used to implement reliable, bidirectional, persistent, point-to
point, stream-based connections between hosts on the Internet.
a)TCP/IP
b)UDP
c)Proxy
d)None of the above

21) _____ can be used to connect Java’s I/O system to other programs that may reside
either on the local machine or on any other machine on the Internet.
a)Server
b)Client
c)Socket
d)All of the above

22) Which class is designed to be a “listener,” which waits for clients to connect
before doing anything?
a)Socket
b)Server
C)Both a & b
d)ServerSocket
23) Which are the two constructors used to create client sockets?
a)Socket(String hostName) ,Socket(InetAddress ipAddress, int port)
b)Socket(String hostName, int port) ,Socket(InetAddress ipAddress)
c)Socket(String hostName, int port), Socket(InetAddress ipAddress, int
port)
d)None of the above

24) By using following methods a socket can be examined at any time for the address
and port information associated with it.
a)InetAddress getInetAddress( )
b)int getPort( )
c)int getLocalPort( )
d)All of the above

25) Which of the following method returns the InetAddress associated with the
Socket object?
a)InetAddress getInetAddress( )b)int getPort( )
c)int getLocalPort( )
d)All of the above

26) Which of the following method returns the remote port to which this Socket
object is connected?
a)InetAddress getInetAddress( )
b)int getPort( )
c)int getLocalPort( )
d)All of the above

27) Which of the following method returns the local port to which this Socket object
is connected?
a)InetAddress getInetAddress( )
b)int getPort( )
c)int getLocalPort( )
d)All of the above

28) Which exception is thrown by the factory methods getLocalHost() & getByName()
when they are unable to resolve the host name?
a)UnknownHostException
b)IOException
c)Both 1 & 2
d)None of the above

29) Which exception is thrown by getAllByName() factory method if it can’t resolve


the name to at least one address?
a)UnknownHostException
b)IOException
c)Both 1 & 2
d)None of the above
30) Which method returns the InputStream associated with the invoking socket?
a)InputStream getInputStream( )
b)OutputStream getOutputStream( )
c)Both 1 & 2
d)None of the above

31) Which method returns the OutputStream associated with the invoking socket?
a)InputStream getInputStream( )
b)OutputStream getOutputStream( )
c)Both 1 & 2
d)None of the above

32) Fill in the blanks in the below program:import ______


class InetAddressTest
{ public static void main(String args[]) throws _______ {
InetAddress Address = InetAddress.____();
System.out.println(Address);
Address = InetAddress._____("osborne.com");
System.out.println(Address);
InetAddress SW[] = InetAddress._____("www.nba.com");
for (int i=0; i<SW.length; i++)
System.out.println(SW[i]); }
}
a)java.net.*; , UnknownHostException, getLocalHost(), getByName,
getAllByName
b)UnknownHostException, getLocalHost(), getByName, getAllByName
c)java.net.* , UnknownHostException, getLocalHost(), getByName,
getAllByName
d)None of the above

33) Which method returns a channel connected to the Socket object?


a)getChannel()
b)getByChannel()
c)getChannelName()
d)Both 1 & 2

34) Which exception is thrown by InetAddress getInetAddress( ), int getPort( ) , int


getLocalPort( ) socket methods?
a)UnknownHostException
b)IOException
c)Both 1 & 2
d)None of the above

35) _______ method Creates a socket connecting the local host to the named host and
port.
a)Socket(String hostName, int port)
b)Socket(InetAddress ipAddress, int port)
c)Both 1 & 2
d)None of the above
36) ______ method Creates a socket using a preexisting InetAddress object and a
port.
a)Socket(String hostName, int port)
b)Socket(InetAddress ipAddress, int port)
c)Both 1 & 2
d)None of the above

37) Fill in the blanks wrt above programimport _______


class WriteServer
{
public static int serverPort = 998;
public static int clientPort = 999;
public static int buffer_size = 1024;
public static______________ ds;
public static byte buffer[] = new byte[buffer_size];
public static void TheClient() throws Exception
{
while(____)
{
DatagramPacket p = new DatagramPacket(buffer, buffer.length);
ds.receive(p);
System.out.println(new String(p.getData(), 0, p.getLength()));
}}
public static void main(String args[]) throws Exception
{
if(args.length == 1)
{
ds = new DatagramSocket(serverPort);
TheServer();
} else
{
public static void TheServer() throws Exception
{
int pos=0;
while (true)
{
int c = System.in.read();
switch (c)
{
case -1:
System.out.println("Server Quits.");
return;
case '\r':
break;
case '\n':
ds.send(new DatagramPacket(buffer,pos,InetAddress.getLocalHost(),clientPort));
pos=0;
break;
default:
buffer[pos++] = (byte) c;
}
}
}
ds = new DatagramSocket(clientPort);
TheClient();
}
}}
a)java.net.* ,DatagramSocket, true
b)java.sql.* ,DatagramSocket,true
c)java.net.* , DatagramPacket,,false
d) java.sql.* ,false, DatagramPacket,,false

38) ds.send(new DatagramPacket(buffer,pos,InetAddress.getLocalHost(),clientPort));


isused for
a)used to send data from client to server.
b)used to send data from server to client.
c)used to send data both ways
d)none of the above

39) ________object is the data container


a)DatagramSocket
b)DataContainer
c)DatagramPacket
d)none of the above

40) DatagramSocket is
a)used to send or receive the DatagramPackets.
b)serialized, predictable, reliable stream of packet data.
c)information passed between machines.
d)none of the above

41) Java implements datagrams by using class/classes


a) DatagramSocket
b)DatagramPackets
c)both a& b
d)none of the above

42) Which is the constructors of Datagram Packet class?


a)DatagramPacket(byte data[ ], int offset, int size)
b)DatagramPacket(byte data[ ], int size, InetAddress ipAddress, int port)
c)DatagramPacket(byte data[ ], int offset, int size, InetAddress ipAddress, int
port)
d)All of the above

43) What does byte[ ] getData( ) method do?


a)Returns the byte array of data contained in the datagram
b)Returns the port number.
c)Returns data in form of string
d)returns length of data
44) which is the method of DataPacket class?
a)InetAddress getAddress( )
b)int getPort( )
c)int getLength( )

d)All of the above

45) Which method returns the destination InetAddress, typically used for sending.
a)int getPort( )
b)int getLength( )
c)InetAddress getAddress( )
d)byte[ ] getData( )

46) It provides a serialized, predictable, reliable stream of packet data


a)TCP
b)UDP
c)URL
d)Datagram

47) When the datagram is received, there is no assurance that it hasn’t been damaged
in trasmissin
a)TRUE
b)FALSE

48) Calling ServerSocket() constructor with port value 'zero' means _____________.
a)use a port number that is automatically allocated.
b)use a local port
c)use server port
d)None of above

49) Which of these package contains classes and interfaces for networking?
a)java.util.*
b)java.networking.*
c)java.net.*
d)java.awt.*

50) A ServerSocket can connect to ________ clients.


a) singleb)Multiple
c) both a and b
d) none of above

51) A socket identifies __________ in network.


a)a communication end point
b)a communication start point
c)Intermediate nodes
d)None of above
52) A_______ is responsible for determining whether code executing in
the Java runtime environment has permission to perform a security sensitive
operation.
a) Permission object
b)security object
c)policy object
d)all of above
53) Connection oriented communication is possible using ________________classes
of Java.
a)Socket and ServerSocket
b)only Socket
c)only ServerSocket
d)DatagramPacket

54) byte[] getData() method of DatagramPacket class returns __________________a)Integer


array of data contained in datagram
b)array of data contained in datagram
c)String array of data contained in datagram
d)Byte array of data contained in datagram

55) In UDP send() and receive() methods belong to which class?


a)DatagramSocket
b)DatagramPacket
c)Socket
d)ServerSocket

56) Java.net package include following classes.


a)URLConnection
b)Socket
c)InetAddress
d)All of above

57) Name the class which is used to create a port where the server will listen?
a)DatagramPacket
b)ServerSocket
c)Socket
d)URL

58) Port Number for FTP is


a)21
b)80
c)20
d)40

59) Pretty Good Privacy (PGP) is used in security of


a)data
b)Email
c) Webpages
d)none of above
60) The constructor for ServerSocket are ______________.
a)ServerSocket(int port, int maxQueue)
b)ServerSocket (int port)
c)ServerSocket(int port, int maxQueue, InetAddress localAddress)
d)All of above

61) The constructor which is used to create client socket is ____________.


a)Socket(InetAddress IPAddress, int port)
b)ServerSocket (int port)
c)Socket(InetAddress IPAddress)
d)all of above

62) The factory method which returns an array of InetAddresses that represent all of
the addresses that a particular host name resolves to.
a)getAllByName( )
b)getByName()
c)getLocalHost( )
d)getHostName( )

63) The java.net.InetAddress class provides methods to get the __________________a)IP of


any host name
b)Host name
c)Domain name
d)All of above

64) URL class has several constructors; each can throw a _____________________.
a)MalformedURLException
b)IOException
c)URLException
d)SocketException

65) What is return type of getAddress() method of InetAddress class?


a)byte[]
b)String[]
c)Array[]
d)Double

66) What is Second part of URL address


a)Filename
b)Hostname
c)portnumber
d)protocol

67) What is the first part of URL address?


a)Filename
b)Hostname
c)portnumber
d)protocol
68) What is the optional part of URL Address
a)Filename
b)Hostname
c)portnumber
d)protocol

69) What is the return type of the method getAllByName( ) of InetAddress class?
a)byte[]
b)String
c)void
d)InetAddress[ ]

70) Which is the reliable protocol of networking ?


a)TCP
b)UDP
c)HTTP
d)FTP

71) Which method is used to return the IPAddress of local machine


a)static InetAddress getLocalHost( )
b)static InetAddress getHost( )c)static InetAddress getPort( )
d)All of above

72) Which method of ServerSocket will wait for a client to initiate communications
and then communicate with the client
a)initialize()
b)start()
c)socket()
d)accept()

73) Which of the following class defines accept() method?


a)Socket
b)ServerSocket
c)DatagramPacket
d)DatagramSocket

74) Which of these is a bundle of information passed between machines?


a)Datagram
b)Frame
c)Packet
d)socket

75) which of these method of DatagramPacket is used to find the length of byte
Array
a)getLength()
b)getlength()
c)getTotalLength()
d)getSize()
76) Which of these method of DatagramPacket is used to find the port number?
a)getPortNumber()
b)getport()
c)getPort()
d)getportNumber()

77) Choose the correct output


import java.net.*;
class myURL2
{
Public static void main(String args[]) throws MalformedURLException
{
URL u=new URL("http://www.msbte.com");
System.out.println("Protocol="+u.getProtocol());
System.out.println("Host Name="+u.getHost());
System.out.println("Port Number="+u.getPort());
System.out.println("File Name="+u.getFile());
}
}
a) Protocol=http Host Name=www.msbte.com Port Number= -1
File Name=
b)Protocol=http Host Name=www.msbte.com Port Number= -1
c)Protocol=http Host Name=www.msbte.com File Name=
d)Protocol=http Host Name=www.msbte.com Port Number= 1

78) Choose the correct output


import java.net.*;
class networking
{Public static void main(String args[])throws UnknownHostException
{
InetAddress obj1 =InetAddress.getByName("msbte.com");
InetAddress obj2 =InetAddress.getByName("msbte.com"); boolean x =
obj1.equals(obj2); System.out.print(x);
}
}
a)true
b)false
c)1
d)-1

You might also like