IMPLEMENTATION OF RMI
Aim:
To implement the RMI for checking whether an number is adam number or not.
1.Adder.java:
import java.rmi.*;
public interface Adder extends Remote{
public int add(int x)throws RemoteException;
2.AdderRemote.java:
import java.rmi.*;
import java.rmi.server.*;
class AdderRemote extends UnicastRemoteObject implements Adder{
AdderRemote()throws RemoteException{
super();
public int ad(int s){
int num=s,a,x,b;
int sqr=num*num;
while(num>0)
X=num%10;
a=a*10+x;
num=num/10;
while(sqr>0)
{
X=sqr%10;
b=b*10+x;
sqr=sqr/10;
Int r=sqrt(b);
If(r==a)
return 0;
else
return 1;
3.MyClient.java:
import java.rmi.*;
import java.util.Scanner;
public class MyClient1{
public static void main(String args[]){
int a,b;
try{
Scanner in =new Scanner(System.in);
Adder stub=(Adder)Naming.lookup("rmi://localhost:5000/sonoo");
System.out.println("Enter any number");
a=in.nextInt();
b=stub.add(a);
if(b==0)
System.out.println("Adam number");
else
System.out.println("Not an adam number");
}catch{Exception e) {System.out.println(e);}
4.MyServer.java:
import java.rmi.*;
import java.rmi.registry.*;
public class MyServer{
public static void main(String args[]){
try{
Adder stub=new AdderRemote();
Naming.rebind("rmi://localhost:5000/sonoo",stub);
}catch{Exception e) {System.out.println(e);}
Output:
Result:
Thus , the implementation of the RMI for checking whether an number is adam
number or not is successfully completed.