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

Networking

Uploaded by

Reyan Dabre
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Networking

Uploaded by

Reyan Dabre
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

What package contains the classes for networking in Java?

Answer: b) java.net

Which class is used to create a socket in Java?


Answer: c) Socket

What does a ServerSocket class do?


Answer: b) Listens for incoming client connections

Which method is used to connect a Socket to a server?


Answer: a) connect()

Which protocol does Java use for networking by default?


Answer: c) TCP

What type of socket is used for connection-oriented communication?


Answer: c) Socket

Which method is called to accept a connection on a ServerSocket?


Answer: b) accept()

What is the default port for HTTP connections?


Answer: c) 80

Which class is used to send and receive UDP packets?


Answer: c) DatagramSocket

Which method is used to send data over a Socket?


Answer: d) getOutputStream()

Which exception is thrown for networking errors in Java?


Answer: a) IOException

What class can be used for URL connections in Java?


Answer: d) All of the above

What is the purpose of the URL class?


Answer: b) Parse URLs

Which method of HttpURLConnection is used to send a request?


Answer: a) connect()

Which method is used to read data from an InputStream?


Answer: a) read()

What type of network communication does TCP provide?


Answer: b) Connection-oriented

What does the bind() method do in a ServerSocket?


Answer: b) Assigns a port number

Which class is used for multicast communication?


Answer: a) MulticastSocket

What is a common use of DatagramSockets?


Answer: c) Real-time gaming

How do you close a Socket in Java?


Answer: b) close()
What is the primary use of a URLConnection?
Answer: c) Handle HTTP requests

What type of stream is used to read data from a URL?


Answer: b) InputStream

Which class provides a mechanism for sending and receiving datagrams?


Answer: b) DatagramSocket

What does the getInputStream() method do?


Answer: b) Returns an InputStream for reading data

What type of addressing does UDP use?


Answer: c) IP Addressing

Which method is used to get the response code from an HTTP connection?
Answer: b) getResponseCode()

What is the function of the Socket constructor?


Answer: b) Create a new socket and connect to a server

What is the primary function of the DatagramPacket class?


Answer: b) Hold UDP packet data

What type of data can be sent using ObjectOutputStream?


Answer: d) All of the above

Which class should be used for HTTP communication in Java?


Answer: b) HttpURLConnection

What method is used to set the timeout for a Socket connection?


Answer: a) setSoTimeout()

Which class is used to represent a URL in Java?


Answer: b) URL

What method of Socket is used to get the port number?


Answer: c) getPort()

Which method is used to read data from a DatagramSocket?


Answer: b) receive()

What does the URLConnection class extend?


Answer: a) Object

Which class is used for handling HTTP requests and responses?


Answer: b) HttpURLConnection

What does the getOutputStream() method return?


Answer: c) OutputStream

Which method is used to connect to a remote server using a URL?


Answer: a) openConnection()

What protocol does HttpURLConnection use?


Answer: b) HTTP

Which method is used to get the content type of a URLConnection?


Answer: a) getContentType()

Which class can handle both TCP and UDP communication?


Answer: d) None of the above

What type of socket does a ServerSocket create?


Answer: b) Listening socket

What is the purpose of the InetAddress class?


Answer: c) Represents an IP address

Which method converts a hostname to an InetAddress?


Answer: a) getByName()

What does the isReachable() method check?


Answer: b) Network reachability

Which exception is thrown when an invalid port number is specified?


Answer: c) IllegalArgumentException

What type of data can be sent using DataOutputStream?


Answer: d) Primitive data types

What does the setReuseAddress() method do?


Answer: a) Allows socket to bind to an address already in use

Which class is used to join a multicast group?


Answer: a) MulticastSocket

What is the purpose of the getLocalAddress() method in Socket?


Answer: b) Returns local IP address

What method is used to get the remote IP address of a Socket?


Answer: a) getInetAddress()

Which protocol does the DatagramPacket class use?


Answer: b) UDP

What type of communication does the FTP protocol facilitate?


Answer: a) File transfer

Which method is used to close a DatagramSocket?


Answer: b) close()

What is the default timeout for socket connections?


Answer: c) Infinite

Which class is used for high-level HTTP operations?


Answer: b) HttpClient

What does the URL class's openStream() method return?


Answer: c) InputStream

Which method is used to set the request method in HttpURLConnection?


Answer: b) setRequestMethod()

What does the send() method in DatagramSocket do?


Answer: a) Sends a datagram packet
Which class can throw an UnknownHostException?
Answer: c) InetAddress

What is the maximum size of a DatagramPacket?


Answer: b) 65507 bytes

Which method is used to flush the output stream?


Answer: a) flush()

What does the getResponseMessage() method return?


Answer: b) HTTP response message

Which method is used to set the request property in HttpURLConnection?


Answer: a) setRequestProperty()

What is the purpose of the NetworkInterface class?


Answer: c) Represents a network interface

What does the getNetworkInterfaces() method return?


Answer: b) Enumeration of network interfaces

Which method is used to obtain the port of a ServerSocket?


Answer: a) getLocalPort()

What type of socket does MulticastSocket extend?


Answer: b) DatagramSocket

What is the purpose of the connect() method in DatagramSocket?


Answer: c) Binds the socket to a specific address

Which class is used to create a secure connection using SSL?


Answer: b) SSLSocket

What does the getInputStream() method of URLConnection return?


Answer: c) InputStream for reading data

Which protocol does the SMTP class support?


Answer: a) Email sending

What is the role of the HttpURLConnection class?


Answer: b) Manage HTTP connections

What is the default port for HTTPS connections?


Answer: c) 443

Which class is used for managing session cookies in HTTP?


Answer: b) CookieManager

What is the primary purpose of a firewall in networking?


Answer: c) Control incoming and outgoing traffic

Which class is used for handling asynchronous sockets?


Answer: a) AsynchronousSocketChannel

What does the term "handshake" refer to in TCP connections?


Answer: b) Connection establishment process

Which method in Socket can change the timeout value?


Answer: a) setSoTimeout()
What is a common use for the InetAddress.getLocalHost() method?
Answer: b) Retrieve the local IP address

Which class is used to send HTTP GET requests?


Answer: b) HttpURLConnection

What does the term "bind" refer to in socket programming?


Answer: a) Assigning a local address to a socket

What is the purpose of the setTrafficClass() method in a Socket?


Answer: c) Set the quality of service parameters

Which class represents an Internet Protocol (IP) address?


Answer: b) InetAddress

What method is used to convert a string to an InetAddress object?


Answer: a) getByName()

Which protocol is used for secure file transfer?


Answer: b) SFTP

What does the getAddress() method in InetAddress return?


Answer: c) byte array representation of the IP address

Which class is responsible for resolving hostnames to IP addresses?


Answer: a) InetAddress

What is the function of the isMulticastAddress() method?


Answer: b) Check if an address is a multicast address

Which class is used for reading and writing data over HTTP?
Answer: b) HttpURLConnection

What method is used to set a socket's timeout value?


Answer: a) setSoTimeout()

Which method is used to retrieve the hostname of an InetAddress?


Answer: b) getHostName()

What is the main purpose of the URLDecoder class?


Answer: c) Decode URL-encoded strings

Which method of DatagramPacket is used to get the data?


Answer: a) getData()

What is the main difference between TCP and UDP?


Answer: b) TCP is connection-oriented; UDP is connectionless

What does the setKeepAlive() method do in a Socket?


Answer: c) Enables keep-alive messages

Which class is used for establishing SSL/TLS connections?


Answer: b) SSLSocket

What is the role of a proxy server in networking?


Answer: a) Acts as an intermediary for requests

Which class is used to represent a multicast socket?


Answer: a) MulticastSocket

What is the purpose of the connect() method in Socket?


Answer: b) Establish a connection to a server

Which class allows sending and receiving packets in a multicast group?


Answer: b) MulticastSocket

What does the method setOOBInline() do in a Socket?


Answer: c) Allows out-of-band data to be inlined

Which class is used to represent a network interface?


Answer: b) NetworkInterface

What is the default buffer size for a Socket's input stream?


Answer: c) 8192 bytes

Which method is used to create a new DatagramPacket?


Answer: a) DatagramPacket()

What does the getLocalHost() method return?


Answer: b) InetAddress of the local host

Which class provides methods for manipulating URL connections?


Answer: a) URLConnection

What is the purpose of the read() method in an InputStream?


Answer: c) Read a byte of data

Which method is used to send an HTTP POST request?


Answer: b) setRequestMethod("POST")

What is the primary function of the DatagramSocket class?


Answer: a) Send and receive datagrams

Which class is used to create a UDP socket in Java?


Answer: b) DatagramSocket

What is the primary purpose of a DatagramPacket?


Answer: a) Hold data for sending or receiving over UDP

Which method is used to send a DatagramPacket?


Answer: a) send()

What method is used to receive a DatagramPacket?


Answer: b) receive()

What type of communication does UDP provide?


Answer: c) Connectionless

Which method retrieves the length of the data in a DatagramPacket?


Answer: a) getLength()

What is the maximum size of a UDP packet?


Answer: b) 65507 bytes

Which method is used to create a new DatagramPacket for receiving data?


Answer: a) DatagramPacket(byte[] buf, int length)
What happens if a DatagramPacket is too large?
Answer: c) It will be truncated

Which class can be used for broadcasting UDP packets?


Answer: b) DatagramSocket

What does the setBroadcast() method do in DatagramSocket?


Answer: a) Allows the socket to send broadcast packets

What is the main difference between DatagramSocket and Socket?


Answer: b) DatagramSocket is for UDP; Socket is for TCP

Which method of DatagramSocket binds it to a specific port?


Answer: a) bind()

What is the purpose of the DatagramSocket constructor that takes a port number?
Answer: b) Create a socket bound to that port

Which method is used to get the address of the sender from a DatagramPacket?
Answer: b) getAddress()

What is the role of the DatagramSocket constructor that takes both port and
address?
Answer: c) Create a socket bound to an address and port

What exception is thrown when a DatagramSocket is created with an invalid port?


Answer: a) SocketException

Which class provides methods for multicast communications in UDP?


Answer: a) MulticastSocket

What does the getData() method in DatagramPacket return?


Answer: b) The byte array containing the packet's data

What happens if a DatagramSocket receives a packet while not bound?


Answer: c) It will throw a SocketException

Which method retrieves the IP address of the local host?


Answer: a) getLocalHost()

What does the getHostName() method return?


Answer: b) The hostname associated with the IP address

Which method is used to check if an InetAddress is reachable?


Answer: a) isReachable()

What type of address does the InetAddress class represent?


Answer: b) IP address

Which method converts a string representation of a hostname to an InetAddress?


Answer: a) getByName()

What does the getCanonicalHostName() method return?


Answer: b) The canonical name for the host

Which method retrieves the raw IP address as a byte array?


Answer: a) getAddress()

What exception can be thrown by the getByName() method?


Answer: b) UnknownHostException

Which method checks if an InetAddress is a loopback address?


Answer: a) isLoopbackAddress()

What type of InetAddress is returned by getByName("localhost")?


Answer: b) Loopback address

You might also like