1. 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.
2. 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(“…”);
connection = url.openConnection();
} catch (MalFormedURLException e) { }
3. 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 java.net package provides two classes–Socket and ServerSocket–which implement the client side of the connection and the server side of the connection, respectively.
4. 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.
5. 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.
6. 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 unable to resolve the host name they throw an UnknownHostException.
7. What does RMI stand for?
It stands for Remote Method Invocation.
8. What is RMI?
RMI is a set of APIs that allows to build distributed applications. RMI uses interfaces to define remote objects to turn local method invocations into remote method invocations.









RMI Programming
http://patriot.net/~tvalesky/easyrmi.html
a review by Lan Chen
This article gives a very simple and good example of how to make a RMI program in JAVA. It provide the basic structure of a RMI program for beginners , so they can imitate the structure and get started. However, since RMI is one of the complex system i n java. It required a good understanding of RPC in order to understand RMI.
How java’s RMI related to Distributed System
Distributed system required tasks running in different address space and virtual machines. In java, there are two method to do this. First is socket. But sockets require client and server to work at application level protocols and message exchanging, w hich requires much detail work. The other is RMI. RMI is based on RPC. RPC abstracts the details to the level of a procedure call. The difference between two is RMI is for object system.
How RMI works
As introduced in the article, there is an simple client-server example
Client side: Client has at least two class. One is the client’s interface for accessing the server’s method. There is no implementation in the interface, just give out the signature.
The other is client program. It uses “lookup” to find the remote object by name in the server’s registry. Then it can access server object through the interface.
Server side: Server should first have a class to implement the interface. Then server also need a program to create an instance of the implementation.
More comparison for RPC and RMI
The basic structure of RPC is as follows:
In java’s RMI, the client access the interface. The rmic complier will automatic generate the client stub and server skeleton. And programmer does not need to consider the communication details. The main structure is nearly same as the above figure, ex cept for its OOP feature.
To conclude, the article is merely a simple introduction for RMI programming. Because of the close relationship between RPC and RMI, to learn RMI would also give a more down-to-ground understanding on how the RPC can be implemented. So I think it is r eally worth to know a little bit of RMI as a supplement of this course.
Interview Questions and answers seems to be useful…tq