aspose file tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Reply Bookmark "RMI Interface " Watch "RMI Interface " New topic
Author

RMI Interface

Tim Adam Cooper
Greenhorn

Joined: Jul 29, 2002
Posts: 17
I am learning about RMI for the Development project. I have written the following programs:
//Interface
import java.rmi.*;
public interface WeatherIntf extends Remote {
public String getWeather() throws RemoteException;
}
//Dummy Class
class Dummy{
public String getWeather(){
return Math.random()>0.5? "sunny" : "rainy";
}
}
//Server Class
import java.rmi.server.*;
import java.rmi.*;
public class Server extends UnicastRemoteObject
implements WeatherIntf {
private Dummy d;
public Server () throws RemoteException {
super();
d = new Dummy();
}
public String getWeather() throws RemoteException {
return d.getWeather();
}
public static void main(String[] args) {
try {
Server myWeatherServer = new Server();
Naming.rebind("//timothycooper/TestServer",myWeatherServer);
System.out.println("Server Ready");
}catch (Exception e) {
System.out.println(e.getMessage() );
}
}
}
//Client Class
import java.rmi.*;
public class Client {
public static void main(String[] args) {
try {
Remote robj = Naming.lookup("//timothycooper/TestServer");
WeatherIntf weatherserver = (WeatherIntf) robj;
String forecast = weatherserver.getWeather();
System.out.println("The weather will be " + forecast );
} catch (Exception e) {System.out.println(e.getMessage());}
}
}
It works with no problem on the network.
Question:
I think that some people will say that the Dummy instance found in the Server class’s constructor probably will not be remoteable and that the Dummy class should implements the WeatherIntf interface.
I ask this question because there seem to be a common approach that in the Java Development FlightNight project that the class Data should implements DataInterface but it look as if the Data class need not implements the DataInterface?
Can anybody shed some light on it?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17243
    
    1

The Data class does not need to implement the DataInterface if you chose not to. In my submission I did not have the Data class implement that interface.
Now by implementing that interface, you can now use the Data class in any class or method that expects a class of DataInterface type. Whereas without implementing the interface, that would not be acceptible.
Pros and Cons are up to you, and others can give you some if they want.
The choice is yours. I prefer if it implemented it, just as a nice design.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: RMI Interface
 
Similar Threads
Rmi BAsic Problem
RMI Hello World between two system?
Help needed in RMI
exception in client side
RMI - packages...