0% found this document useful (0 votes)
10 views3 pages

Manoj

The document contains Java code for a Remote Method Invocation (RMI) application that checks if a given string is a palindrome. It includes an interface 'PalindromeChecker', a server implementation 'PalindromeServer' that processes the palindrome check, and a client 'PalindromeClient' that interacts with the server. The server removes non-alphanumeric characters, converts the string to lowercase, and checks if it reads the same forwards and backwards.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Manoj

The document contains Java code for a Remote Method Invocation (RMI) application that checks if a given string is a palindrome. It includes an interface 'PalindromeChecker', a server implementation 'PalindromeServer' that processes the palindrome check, and a client 'PalindromeClient' that interacts with the server. The server removes non-alphanumeric characters, converts the string to lowercase, and checks if it reads the same forwards and backwards.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Palindrome Checker

import java.rmi.Remote;

import java.rmi.RemoteException;

public interface PalindromeChecker extends Remote {

public boolean checkPalindrome(String s) throws RemoteException;

Palindrome Server

import java.rmi.registry.Registry;

import java.rmi.registry.LocateRegistry;

import java.rmi.RemoteException;

import java.rmi.server.UnicastRemoteObject;

public class PalindromeServer extends UnicastRemoteObject implements PalindromeChecker {

public PalindromeServer() throws RemoteException{

super();

@Override

public boolean checkPalindrome(String s) throws RemoteException {

// remove all non-alphanumeric characters and convert to lowercase

String cleanString = s.replaceAll("[^a-zA-Z0-9]", "").toLowerCase();

// check if the string is equal to its reverse

String reversedString = new StringBuilder(cleanString).reverse().toString();

return cleanString.equals(reversedString);

public static void main(String[] args) {

try {

// create and export the server object

// bind the object to an RMI registry

Registry registry = LocateRegistry.createRegistry(9999);


registry.rebind("PalindromeChecker", new PalindromeServer());

System.out.println("PalindromeChecker server ready.");

catch (RemoteException e) {

System.out.println("exception"+e);

Palindrome Client

import java.rmi.NotBoundException;

import java.rmi.registry.Registry;

import java.rmi.registry.LocateRegistry;

import java.rmi.RemoteException;

import java.util.Scanner;

public class PalindromeClient {

public static void main(String[] args) {

try {

Registry registry = LocateRegistry.getRegistry("localhost", 9999);

PalindromeChecker checker = (PalindromeChecker) registry.lookup("PalindromeChecker");

Scanner scanner = new Scanner(System.in);

System.out.print("Enter a string or number to check for palindrome: ");

String input = scanner.nextLine();


boolean isPalindrome = checker.checkPalindrome(input);

if (isPalindrome) {

System.out.println("\"" + input + "\" is a palindrome.");

} else {

System.out.println("\"" + input + "\" is NOT a palindrome.");

scanner.close();

} catch (NotBoundException | RemoteException e) {

System.err.println("Client exception: " + e.toString());

e.printStackTrace();

You might also like