0% found this document useful (0 votes)
18 views15 pages

Rmi Record Shraddha

Rmi programs

Uploaded by

reshabashetty
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)
18 views15 pages

Rmi Record Shraddha

Rmi programs

Uploaded by

reshabashetty
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/ 15

/*

Program: Write a Java RMI program to accept a String and check whether it has repeated
character in it or not.
Date: 24/11/2023
Reg No:221919
*/
Interface:
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface charRepeat extends Remote{
public boolean repeatchar(String st) throws RemoteException;
}
Implementation:
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
class RepeatCharImpl extends UnicastRemoteObject implements charRepeat{
public RepeatCharImpl() throws RemoteException{
super();
}
public boolean repeatchar(String st) throws RemoteException{
System.out.println("Repeated Characters....");
for(int i=0;i<st.length();i++){
for(int j=i+1;j<st.length();j++){
if(st.charAt(i)==st.charAt(j))
return true;
}
}
return false;
}
}

17
Server:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class RepeatCharServer{
public static void main(String args[]){
try{
RepeatCharImpl obj=new RepeatCharImpl();
Registry reg=LocateRegistry.createRegistry(2800);
reg.rebind("rchar",obj);
System.out.println("Server is Started...");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
Client:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.*;
import java.util.Scanner;
public class RepeatCharClient{
public static void main(String args[]){
try{
Registry reg=LocateRegistry.getRegistry(2800);
charRepeat chk=(charRepeat) reg.lookup("rchar");
System.out.println("Client is accessing...");
System.out.println("Enter the String: ");
Scanner sc=new Scanner(System.in);
String st=sc.next();
if(chk.repeatchar(st))
System.out.println("string has repeated character.");
else
18
System.out.println("string does not has repeated character.");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
OUTPUT:
Compile all files and start RMI registry:

Run the Server program:

Run the Client program:

19
/*
Program: Write a Java RMI program to accept a line of text and display only string which
contains vowels in it.
Date: 01/12/2023
Reg No:221919
*/
Interface:
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface CheckVowel extends Remote{
public boolean isVowel(String st) throws RemoteException;
}
Implementation:
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
class CheckVowelImpl extends UnicastRemoteObject implements CheckVowel{
public CheckVowelImpl() throws RemoteException{
super();
}
public boolean isVowel(String st) throws RemoteException{
System.out.println("finding vowel ....");
for(int i=0;i<st.length();i++){
char ch=Character.toLowerCase(st.charAt(i));
switch(ch){
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':return true;
}
}
return false;

20
}
}
Server:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class CheckVowelServer{
public static void main(String args[]){
try{
CheckVowelImpl obj=new CheckVowelImpl();
Registry reg=LocateRegistry.createRegistry(2800);
reg.rebind("vowel",obj);
System.out.println("Server is Started...");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
Client:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.*;
import java.util.Scanner;
public class CheckVowelClient{
public static void main(String args[]){
try{
Registry reg=LocateRegistry.getRegistry(2800);
CheckVowel chk=(CheckVowel) reg.lookup("vowel");
System.out.println("Client is accessing...");
System.out.println("Enter a String: ");
Scanner sc=new Scanner(System.in);
String st=sc.nextLine();
String[] sarray=st.split(" ");
21
System.out.println("String that contains the vowels are: ");
for(String word:sarray){
if(chk.isVowel(word)){
System.out.print(word + " ");
}
}
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
OUTPUT:
Compile all files and start RMI registry:

Run the Server program:

Run the Client program:

22
/*
Program: Write a Java RMI program to accept a line of text and display each String after
deleting all the repeated characters in it if it contains.
Date: 01/12/2023
Reg No:221919
*/
Interface:
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface deleterchar extends Remote{
public String delrchar(String st) throws RemoteException;
}
Implementation:
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
class deletercharImpl extends UnicastRemoteObject implements deleterchar{
public deletercharImpl() throws RemoteException{
super();
}
public String delrchar(String st) throws RemoteException{
System.out.println("finding vowel ....");
StringBuilder word = new StringBuilder(st);
for (int i = 0; i < word.length(); i++) {
boolean matchFound=false;
for (int j = i + 1; j < word.length(); j++) {
if (word.charAt(i) == word.charAt(j)) {
word.deleteCharAt(j);
matchFound=true;
j--;
}
}
if(matchFound)

23
i--;
}
return word.toString();
}
}
Server:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class deletercharServer{
public static void main(String args[]){
try{
deletercharImpl obj=new deletercharImpl();
Registry reg=LocateRegistry.createRegistry(2800);
reg.rebind("rchar",obj);
System.out.println("Server is Started...");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
Client:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.*;
import java.util.Scanner;
public class deletercharClient{
public static void main(String args[]){
try{
Registry reg=LocateRegistry.getRegistry(2800);
deleterchar chk=(deleterchar) reg.lookup("rchar");
System.out.println("Client is accessing...");
System.out.println("Enter a String: ");
24
Scanner sc=new Scanner(System.in);
String st=sc.nextLine();
String[] sarray=st.split(" ");
System.out.println("String after deleting repeated characters: ");
for(String word:sarray){
System.out.print(chk.delrchar(word) + " ");
}
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
OUTPUT:
Compile all files and start RMI registry:

Run the Server program:

Run the Client program:

25
/*
Program: Write a Java RMI program to accept two strings as command-line arguments and
display the common character among them.
Date: 08/12/2023
Reg No:221919
*/
Interface:
import java.rmi.Remote;
import java.rmi.RemoteException;

public interface commanchar extends Remote{


public String commanch(String s1, String s2) throws RemoteException;
}
Implementation:
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;

class commancharImpl extends UnicastRemoteObject implements commanchar{


public commancharImpl() throws RemoteException{
super();
}
public String commanch(String s1,String s2) throws RemoteException{
System.out.println("Comman charatcters....");
String st="";
StringBuilder st2=new StringBuilder(s2);
for(int i=0;i<s1.length();i++){
for(int j=0;j<st2.length();j++){
if(s1.charAt(i)==st2.charAt(j)){
st=st+s1.charAt(i)+" ";
st2.deleteCharAt(j);
}
}

26
}
return st;
}
}
Server:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class commancharServer{
public static void main(String args[]){
try{
commancharImpl obj=new commancharImpl();
Registry reg=LocateRegistry.createRegistry(2800);
reg.rebind("comman",obj);
System.out.println("Server is Started...");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
Client:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.*;
public class commancharClient{
public static void main(String args[]){
try{
Registry reg=LocateRegistry.getRegistry(2800);
commanchar chk=(commanchar) reg.lookup("comman");
System.out.println("Client is accessing...");
System.out.println("Common characters in two strings -
>"+chk.commanch(args[0],args[1]));
}catch(Exception e){

27
System.out.println(e.getMessage());
}
}
}
OUTPUT:
Compile all files and start RMI registry:

Run the Server program:

Run the Client program:

28
/*
Program: Write a Java RMI program to accept some string as Command-line arguments and
display each string with characters in sorted order.
Date: 08/12/2023
Reg No:221919
*/
Interface:
import java.rmi.Remote;
import java.rmi.RemoteException;

public interface sortstring extends Remote{


public String sort(String st) throws RemoteException;
}
Implementation:
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
import java.util.Arrays;
class sortstringImpl extends UnicastRemoteObject implements sortstring{
public sortstringImpl() throws RemoteException{
super();
}
public String sort(String st) throws RemoteException{
System.out.println("Sorting string charatcters....");
char starray[]=st.toCharArray();
Arrays.sort(starray);
return new String(starray);
}
}
Server:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class sortstringServer{

29
public static void main(String args[]){
try{
sortstringImpl obj=new sortstringImpl();
Registry reg=LocateRegistry.createRegistry(2800);
reg.rebind("sort",obj);
System.out.println("Server is Started...");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
Client:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.*;
public class sortstringClient{
public static void main(String args[]){
try{
Registry reg=LocateRegistry.getRegistry(2800);
sortstring chk=(sortstring) reg.lookup("sort");
System.out.println("Client is accessing...");
for(int i=0;i<args.length;i++){
System.out.println("String After Sorting ->"+chk.sort(args[i]));
}

}catch(Exception e){
System.out.println(e.getMessage());
}
}
}

30
OUTPUT:
Compile all files and start RMI registry:

Run the Server program:

Run the Client program:

31

You might also like