0% found this document useful (0 votes)
59 views9 pages

Java 4TH Chapter - 22517

1. The Socket class is used to create client sockets and accept connections from clients on the server side using ServerSocket.accept(). 2. The InetAddress class provides methods for working with IP addresses like getByName() and getLocalHost() and the getHostAddress() method returns the IP address as a string. 3. The URLConnection class returned by URL.openConnection() allows communication with resources identified by URLs and provides methods for reading, writing and getting metadata about the resource.
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)
59 views9 pages

Java 4TH Chapter - 22517

1. The Socket class is used to create client sockets and accept connections from clients on the server side using ServerSocket.accept(). 2. The InetAddress class provides methods for working with IP addresses like getByName() and getLocalHost() and the getHostAddress() method returns the IP address as a string. 3. The URLConnection class returned by URL.openConnection() allows communication with resources identified by URLs and provides methods for reading, writing and getting metadata about the resource.
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/ 9

AJP (22517)

CHAPTER 4 ~ NETWORKING BASICS

1 Calling ServerSocket() constructor with port 39 The class which encapsulates both the
value 'zero' means______________________. numerical IP address and the domain name for
that address. InetAddress
use a port number that is automatically allocated.
Edit Delete
41 The constructor which is used to create client
socket is ____________.
2 TCP/IP reserves the ____________ ports for
specific protocols Socket(InetAddress IPAddress, int port)
1024
44 The java.net.InetAddress class provides
methods to get the________________________
9 Access control does not deals with
IP of any host name
Authenication

47 The openConnection() is the method of which


11 byte[] getData() method of DatagramPacket Class?
class returns______________________
URLConnection
Byte array of data contained in datagram

49 The return type of getHostAddress() method


20 In UDP send() and receive() methods belong is_____________
to which class?
String
DatagramSocket

50 The server listens for a connection request


21 In which class the constructors are not visible from a client using the following statement
Inetaddress class Socket s = ServerSocket.accept()

24 Java.net package include following classes. 54 To create an InputStream on a Socket s, you


URLConnection, Socket, InetAddress use __________.
InputStream in = s.getInputStream();

26 Permission class of java.security package is


_______ class 55 To obtain an ObjectOutputStream from a
abstract socket,use__________
new
ObjectOutputStream(socket.getOutputStream())
30 Pretty Good Privacy (PGP) is used in security
of
Email 56 To return an instance of InetAddress class you
have to use
Factory Methods of InetAddress class
AJP (22517)
CHAPTER 4 ~ NETWORKING BASICS

57 To return the currently intalled policy 96 Which of the following constructor of


object______________method is used. InetAddress is generally used?
public static Policy getPolicy() InetAddress class does not contain any visible
constructor.

62 URL class has several constructors; each can


throw a _____________________. 99 Which of the following is not a constructor of
MalformedURLException DatagramSocket
DatagramSocket(InetAddress address)
63 What does the openConnection() method of
java.net.* return?
100 Which of the following is not a Factory
Object of URLConnection class method of an InetAddress Class?
String getHostAddress()
65 What is return type of getAddress() method of
InetAddress class?
107 Which of the ServerSocket method listen
byte[] client request for connection?
accept()
81 Which constructor of DatagramSocket class is
used to create a datagram socket and bind it with
the given port number? 112 Which of these is a bundle of information
passed between machines?
DatagramSocket(int port)
Datagram

82 Which datagram method returns the byte array


of data contained in the datagram? 122 Which of these methods is used to know the
full URL of an URL object?
byte[] getData()
toExternalForm()

83 Which exception indicate that the IP address


of a host could not be determined 123 Which of these methods is used to know the
UnknownHostException type of content used in the URL? 3
getContentType()

86 Which is not valid method of URL class?


getUrl() 124 Which of these methods is used to know
when was the URL last modified?
getLastModified()
89 Which method is used to know the full URL
of an URL object?
toExternalForm()
AJP (22517)
CHAPTER 4 ~ NETWORKING BASICS

129 You can obtain the server's hostname by 191 Select proper method used to create the
invoking __________________on an applet. instance InetAddress class.
getCodeBase().getHost()
getLocalHost(),getByName(),getAllByName()

135 __________method is used to examine the


address and port information by the socket. 192 Select the proper interface of java.net
package
getInetAddress()
ContentHandlerFactory

158 Http is which type of Protocol


193 Select the appropriate method for retrieving
Stateless address of remote machine
public Address getRemotHost( )
161 If port number is not specified in the URL,
getPort() method returns _______
196 Select the method used to create a URL
-1 Connection
openConnection
163 If you use either Telnet or FTP, which is the
highest layer you are using to transmit data?
204 Select the proper method to know the type of
Application content used in the URL.
getContentType()
177 In this construtor ServerSocket(int port, int 210 ServerSocket has a method called
maxQueue) what is the default value for __________, which is a blocking call that will
maxQueue? wait for a client to initiate communications,
50 accept()

179 InputStream class is used in TCP Client- 224 The server listens for a connection request
server program to from a client using the following statement:
Send/receive message from client to server Socket s = serverSocket.accept()

184 openConnection() method returns 266 What is the use of bind() method
Returns a URLConnection object bind a socket to a local IP address and port

187 returns the socket and establish a connection 267 What is the use of writeUTF( ) method?
between server and client.
This method writes a string into underlying
public Socket accept() output stream
AJP (22517)
CHAPTER 4 ~ NETWORKING BASICS

285 Which Exception is thrown by socket.getInetAddress();


DatagramSocket class constructor
SocketException

310 You can obtain the server's hostname by


286 Which five parameters uniquely identify a invoking _________ on an applet.
Connection ?
getCodeBase().getHost()
Local IP, Local port, Remote port, Remote IP and
Protocol
311 _______ method is used to examine the
address and port information by the socket.
287 Which ip address is multicast ip address getInetAddress().
235.55.45.2
314 ___________ is a bundle of information
passed between machines.
294 Which is the class present in java.net package
used to create packet from byte array and Datagram
destination address?
DatagramPacket
315 ___________ is a general-purpose class for
accessing the attributes of a remote
295 Which method is used to obtain the Portno of URLConnection
client in Client Program
getLocalPort()
325 A technique that creates a subletting effect;
one server answers ARP requests for multiple
hosts?
296 Which method Returns the output stream of
the URL connection ? Proxy Server
getOutputStream()
326 Which client accesses the Web server by
using a GET MESSAGE?
302 Which of these class is used to encapsulate
IP address and DNS? HTTP
InetAddress
327 Which of these is a protocol for breaking and
sending packets to an address across a network?
303 Which of these methods is used to know host
of an URL? TCIP/IP
getHost()

309 You can invoke ______________ on a


Socket object, say socket, to obtain an
InetAddress object.
AJP (22517)
CHAPTER 4 ~ NETWORKING BASICS

- It uses the package – java.net

• Inet Address -> host name or numerical ip address of the corresponding host
- Factory Methods
1) getLocalHost()
2) getByName()
3) getAllByName()
AJP (22517)
CHAPTER 4 ~ NETWORKING BASICS

• Instance addresses

• TCP/IP Client Sockets

- To Create Client Socket

- Examining the Socket


AJP (22517)
CHAPTER 4 ~ NETWORKING BASICS

• URL:-

- It throws MalformedURLException
- url Format is -> protocol/hostname/port number/file path
- It uses following constructors:-
1) URL(String URLString);
2) URL(String protocolName, String hos, int port, String path)
3) URL(String protocolName, String host, String path)
- Methods are as follows:

- For URL connection OpenConnection() is used


- It uses java.net.URLconnection package to access attributes of remote
resource.
AJP (22517)
CHAPTER 4 ~ NETWORKING BASICS

• TCP/IP SERVER SOCKET


- The Server Socket class is used to create servers that listens to its clients.
- This throws IOException.
- It can be created in the following ways:
1) ServerSocket(int port)
2) ServerSocket(int port, int maxQueue)
3) ServerSocket(int port, int maxQueue, InetAddress localAddress)
- accept() method is used to initiate communication with client.

• Server Program:-
- ServerSocket server_socket=new ServerSocket(1234);
- BufferedReader is for creating the object client_input.
1) getInputStream() - This returns an input stream from the other side.

• Client Program:-
- Socket client_socket=new Socket(“aap”,1234);
- The BufferedReader object is created to read the input from keyboard.
- The InputStreamReader is for reading the stream input.

• Datagrams
- A datagram is an independent, self-contained message.
- The java.net package contains following 3 classes to send receive packets:
1) DatagramSocket
2) DatagramPacket
3) MulticastSocket

• Datagram Packet
- An application can send and receive DatagramPackets through a
DatagramSocket.
- Constructors used:
• DatagramPacket(byte[] barr, int length) : It creates a datagram packet. This
constructor is used to receive the packets.
• DatagramPacket(byte[] barr, int length, InetAddress address, int port) : It
creates a datagram packet. This constructor is used to send the packets.
AJP (22517)
CHAPTER 4 ~ NETWORKING BASICS

You might also like