Step One: Enter and Compile the Source Code Java Help

Step One: Enter and Compile the Source Code

This application uses four source files. The first file, AddServerIntf.java, defines the remote interface that is provided by the server. It contains one method that accepts two double arguments and returns their sum. All remote interfaces must extend the Remote interface, which is part of [java.rmi, Remote defines no members. Its purpose is simply to indicate that an interface uses remote methods. All remote methods can throw a RemoteException.

The second source file, Add Scrvcrlrnpl.java, implements the remote interface. The implementation of the addt ) method is straightforward. All remote objects must extend UntcnstltemotoObjcct, which provides functionality that is needed to make objects available from remote machines. (Currently, only unicast servers are supported. 111 atis, RMI does not support configurations involving replicated servers

The third source file, AddService.java, contains the main program for the server machine. Its primary function is to update the RMI registry on that machine. This is done by using the bind( ) method of the Naming class (found in java.rmi). That method associates a name with an object reference. TIle first argument to the rebind( ) method is a string that names the server as 1/ AddServer. Its second argument is a reference to an instance of AddScrvcrImpl.

The application begins by forming a string that follows the UlU~syntax. This UH.L uses the nni protocol. The string includes the IP address or name of the server and the string AddServer. The program then invokes the lookup() method of the Naming class. This method accepts one argument, the rmi URL, and returns a reference to an .object of type AddServlEt. All remote method invocations can then be directed to this object.

The program continues by displaying its arguments and then invokes the remote addt ) method. Tho S1Ul is returned from this method and is then printed .After you enter. all the code, use Javac to compile the four source files that you created.

JavaHelpOnline.com

  • Feel free to send us an inquiry, we will reply back in hours.
 

Verification

Posted on September 18, 2014 in Additional packages

Share the Story

About the Author

Back to Top