Networking Concepts

1) The API doesn't list any constructors for InetAddress- How do I create an InetAddress instance?

In case of InetAddress the three methods getLocalHost, getByName, getByAllName can be used to create instances. E.g. InetAddress add1; InetAddress add2; try{ add1 = InetAddress.getByName(""); add2 = InetAddress.getByName(""); }catch(UnknownHostException e){}

2) Is it possible to get the Local host IP?

Yes. Use InetAddress's getLocalHost method.

3) What's the Factory Method?

Factory methods are merely a convention whereby static methods in a class return an instance of that class. The InetAddress class has no visible constructors. To create an InetAddress object, you have to use one of the available factory methods. In InetAddress the three methods getLocalHost, getByName, getByAllName can be used to create instances of InetAddress.

4) What’s the difference between TCP and UDP?

These two protocols differ in the way they carry out the action of communicating. A TCP protocol establishes a two way connection between a pair of computers, while the UDP protocol is a one-way message sender. The common analogy is that TCP is like making a phone call and carrying on a two-way communication, while UDP is like mailing a letter.

5) What is the Proxy Server?

A proxy server speaks the client side of a protocol to another server. This is often required when clients have certain restrictions on which servers they can connect to. And when several users are hitting a popular web site, a proxy server can get the contents of the web server's popular pages once, saving expensive internetwork transfers while providing faster

6) What are the seven layers of OSI model?

Application, Presentation, Session, Transport, Network, DataLink, Physical Layer.

7)What Transport Layer does?

It ensures that the mail gets to its destination. If a packet fails to get its destination, it handles the process of notifying the sender and requesting that another packet be sent.

8) What is DHCP?

Dynamic Host Configuration Protocol, a piece of the TCP/IP protocol suite that handles the automatic assignment of IP addresses to clients.

9) What is SMTP?

Simple Mail Transmission Protocol, the TCP/IP Standard for Internet mails. SMTP exchanges mail between servers; contrast this with POP, which transmits mail between a server and a client.

10)What is the difference between URL instance and URLConnection instance?

A URL instance represents the location of a resource, and a URLConnection instance represents a link for accessing or communicating with the resource at the location.

11) How do I make a connection to URL?

You obtain a URL instance and then invoke openConnection on it. URLConnection is an abstract class, which means you can't directly create instances of it using a constructor. We have to invoke openConnection method on a URL instance, to get the right kind of connection for your URL. Eg. URL url; URLConnection connection; try{ url = new URL("..."); conection = url.openConnection(); }catch (MalFormedURLException e) { }

12) What Is a Socket?

A socket is one end-point of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent.Socket classes are used to represent the connection between a client program and a server program. The package provides two classes--Socket and ServerSocket--which implement the client side of the connection and the server side of the connection, respectively.

13)What information is needed to create a TCP Socket?

The Local System’s IP Address and Port Number. And the Remote System's IPAddress and Port Number.

14) What are the two important TCP Socket classes?

Socket and ServerSocket. ServerSocket is used for normal two-way socket communication. Socket class allows us to read and write through the sockets. getInputStream() and getOutputStream() are the two methods available in Socket class.

15)When MalformedURLException and UnknownHostException throws?

When the specified URL is not connected then the URL throw MalformedURLException and If InetAddress’ methods getByName and getLocalHost are unabletoresolve the host name they throwan UnknownHostException.