Saturday, 22 March 2014

49) Write a RMI application to reverse the given string .Write all interfaces and required classes.

import java.rmi.*;
public interface StrRev extends Remote
{
    public String reverse(String str) throws RemoteException;
}


import java.rmi.*;
import java.rmi.server.*;
import java.util.*;
public class StrRev_Impli extends UnicastRemoteObject implements StrRev
{
    public StrRev_Impli() throws RemoteException
    {}

    public String reverse(String str) throws RemoteException
    {
        String str1="";
        for(int i=str.length()-1;i>=0;i--)
            str1=str1+str.charAt(i);
        return (str1);
    }
}


import java.rmi.*;
import java.net.*;
public class StrRev_Server
{
    public static void main(String args[])
    {
        try
        {
        StrRev_Impli strimpli=new StrRev_Impli();
        Naming.rebind("RmiReverse",strimpli);
        }
        catch(Exception ex){}
    }
}


import java.io.*;
import java.rmi.*;
import java.net.*;
public class StrRev_Client
{
    public static void main(String args[])
    {
        try
        {
            String url="rmi://127.0.0.1/RmiReverse";
            StrRev strf=(StrRev)Naming.lookup(url);

            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            System.out.println("Enter String to reverse : ");
            String str=br.readLine();
            System.out.println("Reverse of entered string is "+strf.reverse(str));
        }
        catch(Exception ex){}
    }
}

2 comments:

  1. Excellent…Amazing…. I’m satisfied to find so many helpful information here within the put up,for latest php jobs in near me. we want work out extra strategies in this regard, thanks for sharing.

    ReplyDelete