You are on page 1of 14

EX.

NO:1 DISPLAYING THE DATE AND TIME OF A SERVER


DATE:
DISPLAYING THE DATE AND TIME OF A SERVER

SOURCE CODE:

INTERFACE
import java.rmi.*;
public interface dateinter extends Remote
{
public String datetime() throws RemoteException;
}

SERVER
import java.rmi.*;
import java.rmi.server.*;
import java.util.*;
import java.text.*;
public class dateserver extends UnicastRemoteObject implements dateinter
{
public dateserver()throws RemoteException
{}
public String datetime() throws RemoteException
{
Date d=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("hh:mm:ss");
String t=(sdf.format(d)).toString();
sdf=new SimpleDateFormat("dd/mm/yyyy");
t+=" "+(sdf.format(d)).toString();
return t;
}
public static void main(String args[]) throws Exception
{
dateserver s=new dateserver();
try
{
System.out.println("Binding into rmi registry");
Naming.rebind("dateserverobj",s);
System.out.println("main method of the server terminated");
}
catch(Exception e)
{
System.out.println("error occurred:"+e);
}
}
}
CLIENT
import java.rmi.*;
public class cliex2
{
public static void main(String args[])throws Exception
{
try
{
dateinter i=(dateinter)Naming.lookup("rmi://localhost/serex2obj");
System.out.println("The time and date in the server is"+i.datetime());
}
finally
{
}
}
}

SAMPLE INPUT AND OUTPUT

E:\JAVA>javac dateinter.java
E:\JAVA>javac dateserver.java
E:\JAVA>rmic dateserver
E:\JAVA>start rmiregistry
E:\JAVA>java dateserver

CLIENT
E:\JAVA>javac dateclient.java
E:\JAVA>java dateclient
The time and date in the server is
03:05:55 06/08/2015
EX.NO:2 DISPLAYING EVEN SERIES FOR THE GIVEN NUMBER
DATE:
DISPLAYING THE EVEN SERIES FOR THE GIVEN NUMBER

SOURCE CODE:

INTERFACE
import java.rmi.*;
public interface inter extends Remote
{
String even(int n)throws RemoteException;
}
SERVER
import java.rmi.*;
import java.rmi.server.*;
import java.net.*;
public class evenserver extends UnicastRemoteObject implements inter
{
public evenserver()throws RemoteException
{}
public String even(int n)throws RemoteException
{
int i,;
String s="";
for(i=1;i<=n;i++)
{
if(i%2==0)
{
s=s+i+"";
}}
return(s);
}
public static void main(String args[])throws Exception
{
evenserver s3=new evenserver();
try
{
System.out.println("Binding into the RMI registry");
Naming.rebind("evenserverobj",s3);
System.out.println("Main method of the server terminated");
}
catch(Exception e)
{
}
}
}
CLIENT
import java.rmi.*;
import java.net.*;
import java.io.*;
public class evenclient
{
public static void main(String args[])throws Exception
{
try
{
String s;
DataInputStream d=new DataInputStream(System.in);
even_inter s3=(even_inter)Naming.lookup("rmi://localhost/evenserverobj");
System.out.println("Enter the limit:");
int n=Integer.parseInt(d.readLine());
System.out.println("The even series are:");
s=s3.even(n);
System.out.println(s);
}
catch(Exception e)
{
}
}
}

SAMPLE INPUT AND OUTPUT

E:\JAVA>javac even_inter.java
E:\JAVA>javac evenserver.java
E:\JAVA>rmic evenserver
E:\JAVA>start rmiregistry
E:\JAVA>java evenserver
Binding into RMI registry
Main method of the server terminated

CLIENT
E:\JAVA>javac evenclient.java
E:\JAVA>java evenclient
Enter the limit:
10
The even series is:
0246810
EX.NO:3 DISPLAYING FIBONACCI SERIES FOR THE GIVEN NUMBER
DATE:
DISPLAYING FIBONACCI SERIES FOR THE GIVEN NUMBER

SOURCE CODE:

INTERFACE
import java.rmi.*;
public interface fibointer extends Remote
{
String fibo(int n)throws RemoteException;
}
SERVER
import java.rmi.*;
import java.rmi.server.*;
import java.net.*;
public class fiboserver extends UnicastRemoteObject implements fibointer
{
public fiboserver()throws RemoteException
{}
public String fibo(int n)throws RemoteException
{
int i,a=0,b=1,c;
String s="0"+""+"1";
for(i=1;i<=n-2;i++)
{
c=a+b;
s=s+""+c+"";
a=b;
b=c;
}
return(s);
}
public static void main(String args[])throws Exception
{
fiboserver s3=new fiboserver();
try
{
System.out.println("binding into the RMI registry");
Naming.rebind("fiboserverobj",s3);
System.out.println("main method of the server terminated");
}
catch(Exception e)
{
}
}
}
CLIENT
import java.rmi.*;
import java.net.*;
import java.io.*;
public class client3
{
public static void main(String args[])throws Exception
{
try
{
String s;
DataInputStream d=new DataInputStream(System.in);
fibointer s3=(fibointer)Naming.lookup("rmi://localhost/server3obj");
System.out.println("Enter the limit:");
int n=Integer.parseInt(d.readLine());
System.out.println("The fibonacci series are:");
s=s3.fibo(n);
System.out.println(s);
}
catch(Exception e)
{
}
}
}

SAMPLE INPUT AND OUTPUT

E:\JAVA>javac fibointer.java
E:\JAVA>javac fiboserver.java
E:\JAVA>rmic evenserver
E:\JAVA>start rmiregistry
E:\JAVA>java fiboserver
Binding into RMI registry
Main method of the server terminated

CLIENT
E:\JAVA>javac fiboclient.java
E:\JAVA>java fiboclient
Enter the limit:
10
The fibonacci series is:
0112358132134
EX.NO:4 MANIPULATION OF VARIOUS STRING OPERATIONS
DATE:
MANIPULATION OF VARIOUS STRING OPERATIONS

SOURCE CODE:

INTERFACE
import java.rmi.*;
public interface inter4 extends Remote
{
String con(String s1,String s2)throws RemoteException;
String len(String s)throws RemoteException;
String comp(String s1,String s2)throws RemoteException;
String sub(String s1,int pos,int len)throws RemoteException;
}
SERVER
import java.rmi.*;
import java.rmi.server.*;
import java.net.*;
public class server4 extends UnicastRemoteObject implements inter4
{
public server4()throws RemoteException
{
}
public String con(String s1,String s2)throws RemoteException
{
return("the concatenation of two string is:"+s1+s2);
}
public String len(String s)throws RemoteException
{
return("the length of the given string is:"+s.length());
}
public String comp(String s1,String s2)throws RemoteException
{
if(s1.compareTo(s2)>0)
return("the first String is greater than second string");
else if(s1.compareTo(s2)>0)
return ("the first string is smaller than second string");
else
return("the two string are equal");
}
public String sub(String s,int pos,int len)throws RemoteException
{
return("the requried String is:"+s.substring(pos,len));
}
public static void main(String args[])throws RemoteException
{
server4 s4=new server4();
try
{
System.out.println("Binding into the RMI registry");
Naming.rebind("server4obj",s4);
System.out.println("Main method of the server terminated");
}
catch(Exception e)
{
}
}
}
CLIENT
import java.rmi.*;
import java.net.*;
import java.io.*;
public class cli4
{
public static void main(String args[])throws Exception
{
try
{
String str1,str2,s1,s2,ch="y",c="y";
DataInputStream d=new DataInputStream(System.in);
inter4 s4=(inter4)Naming.lookup("rmi://localhost/server4obj");
do
{
System.out.println("\n 1.concatenation \n 2.length\n 3.compare\n 4.Substring\n5.exit");
System.out.println("enter ur choice:");
int n=Integer.parseInt(d.readLine());
switch(n)
{
case 1 :
System.out.println("enter the first string:");
str1=d.readLine();
System.out.println("enter the second string:");
str2=d.readLine();
System.out.println(s4.con(str1,str2));
System.out.println("do u want to continue>(y/n):");
ch=d.readLine();
break;
case 2:
System.out.println("enter the string:");
str1=d.readLine();
System.out.println(s4.len(str1));
System.out.println("do u want to continue>(y/n):");
ch=d.readLine();
break;
case 3:
System.out.println("enter the first string:");
str1=d.readLine();
System.out.println("enter the second string:");
str2=d.readLine();
System.out.println(s4.comp(str1,str2));
System.out.println("do u want to continue>(y/n):");
ch=d.readLine();
break;
case 4:
System.out.println("enter the first string:");
str1=d.readLine();
System.out.println("enter the starting position:");
int i=Integer.parseInt(d.readLine());
System.out.println("enter the ending position:");
int j=Integer.parseInt(d.readLine());
System.out.println(s4.sub(str1,i-1,j));
System.out.println("do u want to continue>(y/n):");
ch=d.readLine();
break;
case 5:
System.exit(0);
break;
}
}
while(ch.equals(c));
}
catch(Exception e)
{
}
}
}

SAMPLE INPUT AND OUTPUT


E:\JAVA>javac inter4.java
E:\JAVA>javac server4.java
E:\JAVA>rmic server4
E:\JAVA>start rmiregistry
E:\JAVA>java server4
Binding into RMI registry
Main method of the server terminated

CLIENT
E:\JAVA>javac cli4.java
E:\JAVA>java cli4
1.concatenation
2.length
3.compare
4.Substring
5.exit
enter your choice:1
enter the first string:siva
enter the second string:ji
the concatenation of two string is:sivaji
do u want to continue>(y/n):y

1.concatenation
2.length
3.compare
4.Substring
5.exit
enter your choice:2
enter the string:sivaji
the length of the given string is:6
do u want to continue>(y/n):y

1.concatenation
2.length
3.compare
4.Substring
5.exit
enter your choice:3
enter the first string:siva
enter the second string:ramu
The two Strings are equal
do u want to continue>(y/n):y

1.concatenation
2.length
3.compare
4.Substring
5.exit
enter your choice:4
enter the first string:aswini
enter the starting position:1
enter the ending position:4
the required string is:aswi
do u want to continue>(y/n):y

1.concatenation
2.length
3.compare
4.Substring
5.exit
enter your choice:5

You might also like