Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

MCQs on DatagramPacket

1. Connection oriented communication is possible using ____________ classes of Java.


a) Socket and ServerSocket
b) DatagramSocket and DatagramPacket
c) Both of these
d) None of these
Answer: c) Both of these

2. Which constructor of DatagramPacket class are used for receiving purpose?


a) DatagramPacket(byte data[ ], int size) DatagramPacket(byte data[ ], int size, int
offset, int port)
b) DatagramPacket(byte data[ ], int size, InetAddress ip, int port)
DatagramPacket(byte data[ ], int offset, int size, InetAddress ip, int port)
c) DatagramPacket(byte data[ ], int size) DatagramPacket(byte data[ ], int size,
InetAddress ip, int port)
d) All of these
Answer: d) All of these

3. byte[] getData() method of DatagramPacket class returns__________.


a) Bytes of data
b) Byte array of data contained in datagram
c) None of these
d) All of these
Answer: b) Byte array of data contained in datagram.

4. UDP Protocol uses following classes for communication


a) DatagramPacket and DatagramSocket
b) Only DatagramPacket
c) SeverSocket and Server
d) None of these
Answer: a) DatagramPacket and DatagramSocket

5. Which of these is a return type of getAddress method of DatagramPacket class?


a) inetaddress
b) Inetaddress
c) InetAddress
d) None of these
6. Which of these is a return type of getData() method of DatagramPacket class
a) byte
b) getdata
c) GetData
d) None of these
Answer: a) byte

7. Which of these method does not belong to DatagramPacket class?


a) getByte
b) getData
c) getAddress()
d) None of these
Answer: c) getAddress()

8. _______ method of DatagramSocket class is used to receive DatagramPacket.


a) Get(DatagramPacket packet)
b) receive(DatagramPacket packet)
c) Get(datagrampacket packet)
d) None of these
Answer: b) receive(DatagramPacket packet)

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

11. Select correct constructors of DatagramPacket class?


a) datagrampacket(int size) DatagramPacket(int offset ,int size)
b) DatagramPacket(byte data[],int size) DatagramPacket(byte data[],int offset ,int
size)
c) datagrampacket(byte data[],int size) DatagramPacket(byte data[],int offset ,int
size)
d) None of these
Answer: b) DatagramPacket(byte data[],int size) DatagramPacket(byte data[],int
offset ,int size)

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

16. Which of these is a bundle of information passed between machines?


a) Mime
b) Cache
c) Datagrams
d) DatagramSocket
Answer: C) Datagrams

17. Which of these class is necessary to implement datagrams?


a) DatagramPacket
b) DatagramSocket
c) All of the mentioned
d) None of the mentioned
Answer: C) all of the mentioned

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

23. Which of these is a return type of getAddress() method of DatagramPacket class?


a) DatagramPacket
b) DatagramSocket
c) InetAddress
d) ServerSocket
Answer:C) InetAddress

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

25. Each method is established a connection between server and client.


A) accept ()
B) open()
C) get Localhost()
D) Openconnection
Answer: a) accept
26. A socket is consist of ?
a) port + IP address
b)only IP address
c)only port address
d)none of the above
Answer: a) port + IP address

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

29. Which packet implements is Connectionlesss paket delivery service


a)server socket
b) datagrampaket
c) Inetserver
d) datagramSocket
Answer: B) datagrampaket

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)

31. ServerSocket class creates ________ a specified port.


a) TCP
b) UDP
c) HTTP
d) None of these
Answer: a) TCP
32. Datagram packet implement a ________ delivery service.
a) Connection packet
b) Connection less packet
c) All of these
d) None of these
Answer: b) Connection less packet

33. accept metmethod is established a connection between ______


a) Server and client
b) Server
c) Client
d) None of these
Answer: a) Server and client

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)

35. Which class defines following method


int getContentLength()
Long getDate()
Long getExpiration()
a) URL connection less
b) URL connection
c) All of these
d) None of these
Answer: b) URL connection

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()

37. getData() method to retrieve the data from ________


a) Datagramsocket
b) datagramsocket
c) DatagramSocket
d) None of these
Answer: c) DatagramSocket

38. getPort method of datagram is used to find ________


a) Port number
b) URL
c) InetAddress
d) None of these
Answer: a) Port number

39. Datagram packet and datagram socket is used for _____


a) Socket programming
b) Connection less socket programming
c) Connection socket programming
d) None of these
Answer: b) Connection less socket programming

40. Inetaddress is the return type of ________


a) Datagram packet class
b) Datagram socket class
c) All of these
d) None of these
Answer: a) Datagram packet class

41. Socket and Server Socket are_________


a) URL
b) InetAddress
c) Connection oriented communication
d) None of these
Answer: c) Connection oriented communication

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

43. Open connection method of URL class returns.


a) Object of InetAddress class
b) Object of URL connection class
c) All of these
d) None of these
Answer: b) Object of URL connection class
44. UDP is called a _______ transport protocol.
a) Unreliable
b) All of these
c) None of these
Answer: a) Unreliable

45. UDP packets are encapsulated in _______


a) An UP datagram
b) An IP datagram
c) All of these
d) None of these
Answer: b) An IP datagram

You might also like