Professional Documents
Culture Documents
AJP DatagramPacket MCQ
AJP DatagramPacket MCQ
9. Given the following lines from a Java program segment: byte[] dataOut = new byte
[512]; String userInput = "Java Programming"; dataOut = userInput.getBytes(); Which of
the following lines of code could be used to create a new UDP datagram packet to send
the data that was provided by the user to a host identified by the InetAddress object
IPAddress?
a) DatagramPacket packet = new DatagramPacket(dataOut, userInput.length,
InetAddress, 9876)
b) datagramPacket packet = new datagramPacket(dataOut, userInput.length,
InetAddress, 9876)
c) Datagrampacket packet = new Datagrampacket(dataOut, userInput.length,
InetAddress, 9876)
d) None of these
Answer: a) DatagramPacket packet = new DatagramPacket(dataOut,
userInput.length, InetAddress, 9876)
10. If we create the datagram packet with following constructor: DatagramPacket (byte
data[],int offset, int size, InetAddress ipaddress, int port) What "size" parameter
specifies?
a) size of InerAddress
b) Size of data
c) size of the packet
d) None of these
Answer: c) size of packet
12. select the proper method to retrive the data from DatagramPacket
a) getData()
b) GetData()
c) Data()
d) None of these
Answer: a) getData()
13. Which is the class present in java.net package used to create packet from byte array and
destination address?
a) DataGramPacket
b) datagrampacket
c) DatagramPacket
d) None of these
Answer: DatagramPacket
14. Write a syntax to prepare DatagramPacket Object as sendPacket by using other parameter
as following. InetAddress IPAddress = InetAddress.getByName("127.0.0.1"); byte[]
sendData = new byte[1024]; int port=9876; String sentence = inFromUser.readLine();
sendData = sentence.getBytes();
a) DatagramPacket sendPacket=DatagramPacket(sendData, sendData.length,
IPAddress, port);
b) datagrampacket sendPacket=datagrampacket(sendData, sendData.length,
IPAddress, port);
c) Datagrampacket sendpacket=Datagrampacket(senddata, sendData.length,
IPaddress, port);
d) None of these
Answer: a) DatagramPacket sendPacket=DatagramPacket(sendData,
sendData.length, IPAddress, port);
15. byte[] getData() method of DatagramPacket class returns______________
a) array of data
b) Byte array of data contained in datagram
c) All of these
d) None of these
Answer: b) Byte array of data contained in datagram
18. Which of these method of DatagramPacket is used to find the port number?
a) port()
b) getPort()
c) findPort()
d) recievePort()
Answer:B) getport
19. Which of these method of DatagramPacket is used to obtain the byte array of data contained
in a datagram?
a) getData()
b) getBytes()
c) getArray()
d) recieveBytes()
Answer:A) getdata
20. Which of these methods of DatagramPacket is used to find the length of byte array?
a) getnumber()
b) length()
c) Length()
d) getLength()
Answer: D) getlength
21. which of these class must be used to send a datagram packets over a connection?
a) InetAdress
b) DatagramPacket
c) DatagramSocket
d) All of the mentioned
Answer:. D) all of the mentioned
22. Which of these method of DatagramPacket class is used to find the destination address?
a) findAddress()
b) getAddress()
c) Address()
d) whois()
Answer:B) getaddress
24. 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.
a) getSocketAddress()
b) getAddress()
c) address()
d) none of the mentioned
Answer:A) getSocketAddress
27. Which method of URL class returs the object of URL connection of class
a) getLocalHost()
b) openconnection
c) getByname ( string host)
d) gethost adress
Answer: b) openconnection
28. Which class creates a tcp server socket bound to the specified port?
a) socket
b)Inetadress
C) server socket
D) Datagrampoket
Answer: C) server socket
30. Which class are used for connection less socket programming
a) datagrampaket
b) datagramSocket
c) none of the above
d) Both A) & b)
Answer: D) both a) & b)
34. which construct of DatagramSocket is used to creates a datagram socket and binds it with
the a port number
a) datagramsocket (int port, InetAddress address)
b) DatagramSocket (int port)
c) DatagramSocket (int port, InetAddress address)
d) None of these
Answer: c) DatagramSocket (int port,InetAddress address)
36. __________ method of DatagramSocket class returns byte array of data contained in
datagram.
a) getdata()
b) Byte[] getdata()
c) Byte[]
d) None of these
Answer: b) Byte[] getdata()
42. _______ Protocol are use Datagram packet and Datagram Socket classes for communication
a) HTTP
b) UDP
c) TCP
e) None of these
Answer: b) UDP