AIM:
To write a Java program for the implementation of Remote Method Invocation for palindrome.
ALGORITHM:
SERVER SIDE:
Step 1: Start
Step 2: Define the class rmiserver
Step 3: Create the object twox in try
Step 4: Register the object twox
Step 5: Display the exception in catch
Step 6: Stop
CLIENT SIDE:
Step 1: Start
Step 2: Define the class rmiclient
Step 3: Initialize the string s1 in try
Step 4: Create and Initialize the object onex
Step 5: Assign the value to m by calling the method palin
Step 6: Check whether the string is palindrome or not
Step 7: Display whether the string is palindrome or not
Step 8: Display the exception in catch
Step 9: Stop
SOURCE CODE:
one.java
import java.rmi.*;interface one extends Remote
{
public int palin(String a) throws RemoteException;
}
two.java
import java.rmi.*;import java.lang.*;
import java.rmi.server.*;
public class two extends UnicastRemoteObject implements one
{
public two() throws RemoteException { }
public int palin(String a) throws RemoteException
{
System.out.println("Hello");
StringBuffer str = new StringBuffer(a);
String str1 = str.toString();
System.out.println("Print : " + str1.toString());
StringBuffer str2 = str.reverse();
System.out.println("Print : " + str2.toString());
int b = str1.compareTo(str2.toString());
System.out.println("Print : " + b);
if (b == 0)
return 1;
else
return 0;
}
}
rmiserver.java
import java.io.*;import java.rmi.*;
import java.net.*;
public class rmiserver
{
public static void main(String args[]) throws Exception
{
try
{
two twox = new two();
Naming.bind("palin", twox);
System.out.println("Object registered");
}
catch(Exception e)
{
System.out.println("Exception" + e);
}
}
}
rmiclient.java
import java.io.*;import java.rmi.*;
import java.net.*;
public class rmiclient
{
public static void main(String args[]) throws Exception
{
try
{
String s1 = "rmi://localhost/palin";
one onex = (one)Naming.lookup(s1);
int m = onex.palin("madam");
System.out.println("Print : " + m);
if (m == 1)
{
System.out.println("The given string is a Palindrome");
}
else
{
System.out.println("The given string is not a Palindrome");
}
}
catch (Exception e)
{
System.out.println("Exception" + e);
}
}
}
OUTPUT:
SERVER SIDE:
CLIENT SIDE:
RESULT:
Thus the Java program for the implementation of Remote Method Invocation for palindrome was performed and the output was verified.
.
EmoticonEmoticon