RMI program for find factorial of a number
RMI interface
import java.rmi.*;
public interface myInterface extends Remote
{
double fact(int i)throws RemoteException;
}
public interface myInterface extends Remote
{
double fact(int i)throws RemoteException;
}
RMI server
import java.rmi.*;
import java.rmi.server.*;
public class myServer extends UnicastRemoteObject implements myInterface
{
public myServer()throws RemoteException
{
super();
}
public double fact(int i)throws RemoteException
{
int f=1;
int n=1;
while(n<=i)
{
f=f*n;
n++;
}
return(f);
}
public static void main(String args[])
{
try{
myServer ms=new myServer();
Naming.rebind("rmi://hsj./myInterface",ms);
import java.rmi.server.*;
public class myServer extends UnicastRemoteObject implements myInterface
{
public myServer()throws RemoteException
{
super();
}
public double fact(int i)throws RemoteException
{
int f=1;
int n=1;
while(n<=i)
{
f=f*n;
n++;
}
return(f);
}
public static void main(String args[])
{
try{
myServer ms=new myServer();
Naming.rebind("rmi://hsj./myInterface",ms);
/* bolded area must replace with your computer name */
System.out.print("Start...");
}
System.out.print("Start...");
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
}
RMI Client
import java.io.*;
import java.rmi.*;
public class myClient
{
public static void main(String args[])throws IOException,RemoteException
{
int no;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a no:");
no=Integer.parseInt(br.readLine());
try{
myInterface mi=(myInterface)Naming.lookup("rmi://hsj./myInterface");
double f=mi.fact(no);
System.out.print("Factorial of "+no+" is:"+f );
}
catch(Exception ex)
{
}
}
}
import java.rmi.*;
public class myClient
{
public static void main(String args[])throws IOException,RemoteException
{
int no;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a no:");
no=Integer.parseInt(br.readLine());
try{
myInterface mi=(myInterface)Naming.lookup("rmi://hsj./myInterface");
double f=mi.fact(no);
System.out.print("Factorial of "+no+" is:"+f );
}
catch(Exception ex)
{
}
}
}
output
RMI Server |
RMI Client |
very nice tutorial. its so simple to understand. i finally get it. and i managed to run it correctly. thank you! :))
ReplyDelete
ReplyDeleteThis is quite educational arrange. It has famous breeding about what I rarity to vouch. Colossal proverb.
This trumpet is a famous tone to nab to troths. Congratulations on a career well achieved. This arrange is synchronous s informative impolites festivity to pity. I appreciated what you ok extremely here
Selenium training in bangalore
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
This comment has been removed by the author.
ReplyDeleteYour site is amazing and your blogs are informative. I have bookmarked this blog for my reference.
ReplyDeleteSalesforce Training | Online Course | Certification in chennai | Salesforce Training | Online Course | Certification in bangalore | Salesforce Training | Online Course | Certification in hyderabad | Salesforce Training | Online Course | Certification in pune
First i got a great blog .I will be interested in more similar topics. i see you got really very useful topics, i will be always checking your blog thanks.
ReplyDeletehardware and networking training in chennai
hardware and networking training in porur
xamarin training in chennai
xamarin training in porur
ios training in chennai
ios training in porur
iot training in chennai
iot training in porur
Thank You and that i have a keen offer you: How Much Remodel House split level house exterior remodel
ReplyDelete