// Step 2. Create Interface Implementation: TimeStampImpl.java import java.util.*; import java.lang.*; import java.rmi.*; import java.rmi.server.*; // The UnicastRemoteObject class defines a non-replicated remote object whose references are // valid only while the server process are running. It provides support for point-to-point active // object references (invocations, parameters, and results) and requires a TCP based connection. public class TimeStampImpl extends UnicastRemoteObject implements TimeStampIF { // serviceName: holds the name of the service to be registered private String serviceName; // Create the constructor. // The constructor must throw java.rmi.RemoteException, in case an attempt to export // a remote object fails due to a communication break. public TimeStampImpl(String s) throws RemoteException { super(); serviceName = s; } // getTimeStamp – the method to be used by the client. // Returns the current date and time as a string. public String getTimeStamp() throws RemoteException { Calendar exactTime = Calendar.getInstance(); String exactTimeStr = (String)(exactTime.getTime()).toString(); return exactTimeStr; } static public void main(String args[]) { // start the RMISecurityManager // acts as a watchdog for all remotely loaded objects – it disables all // functions except class definition and access. System.setSecurityManager(new RMISecurityManager()); // try to register the remote object (TimeStampService) on the server // using the URL based binding mechanism provided by Java RMI implementation. try { TimeStampImpl obj = new TimeStampImpl("TimeStampService"); Naming.rebind("//serverNameIP/TimeStampService", obj); System.out.println("TimeStampService registered"); } catch (Exception e) { System.out.println("TimeStampImpl err: " + e.getMessage()); e.printStackTrace(); } // end of try/catch excepition } // end of main } // end of TimeStampImpl.class