[go: up one dir, main page]

0% found this document useful (0 votes)
72 views6 pages

RMI Implementation for Adam Number

This document outlines the implementation of a Remote Method Invocation (RMI) to check if a number is an Adam number. It defines an interface called Adder with a method to add numbers. It then creates an AdderRemote class that implements the interface and defines the add method logic. A client class is created to lookup and call the remote add method, passing a number and receiving the result. A server class binds the remote object to allow the client to access it. The output shows the implementation was successful.

Uploaded by

jeganathan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views6 pages

RMI Implementation for Adam Number

This document outlines the implementation of a Remote Method Invocation (RMI) to check if a number is an Adam number. It defines an interface called Adder with a method to add numbers. It then creates an AdderRemote class that implements the interface and defines the add method logic. A client class is created to lookup and call the remote add method, passing a number and receiving the result. A server class binds the remote object to allow the client to access it. The output shows the implementation was successful.

Uploaded by

jeganathan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

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.

You might also like