Java Tutorial

 
 
 
 
// revsent.idl

module revsent_val
{
  interface revsent
  {
    string getstr(in string a);
  };
};


// revsent_client.java

import revsent_val.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.io.*;
import java.lang.*;
public class revsent_client
{
    static revsent revsentimpl;
    public static void main(String args[])
    {
      try
      {

        String result_str,tempstr;
        ORB orb=ORB.init(args,null);
        org.omg.CORBA.Object objref=orb.resolve_initial_references(\"NameService\");

        NamingContextExt ncref=NamingContextExtHelper.narrow(objref);

        String pathname=\"revsent\";
        revsentimpl=revsentHelper.narrow(ncref.resolve_str(pathname));

        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

        System.out.println(\"Enter string you want to send to server : \");
        tempstr=in.readLine();
        StringBuffer string1=new StringBuffer(tempstr);

        System.out.println(\"String sent to server : \"+string1);

        result_str=revsentimpl.getstr(string1.toString());

        System.out.println(\"String recvd from server is as below:\");
        System.out.println(result_str);

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

}


// revsent_server.java

import revsent_val.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
import java.lang.*;
import java.util.*;

class serverimpl extends revsentPOA
{
   private ORB orb;
   public void setorb(ORB orb_val)
   {
      orb=orb_val;
   }

   public String getstr(String str1)
   {
     StringBuffer strb1=new StringBuffer(str1);
     strb1.insert(0,\' \');
     String ans_str=\"\";
     int len=strb1.length()-1;
     int j=0;
     System.out.println(\"length:\"+len);

     for(int i=len;i>=0;i--)
     {
       if(strb1.charAt(i)==\' \')
         {
          ans_str+=strb1.substring(i+1,len+1);
          j=i-1;
          break;
        }
     }

     for(int i=j;i>=0;i--)
     {
       if(strb1.charAt(i)==\' \' || i==0)
         {
          ans_str+=strb1.substring(i,j+1);
          j=i-1;
          }
     }

     return(ans_str);
   }
}
public class revsent_server
{
   public static void main(String args[])
   {
     try
     {
         ORB orb=ORB.init(args,null);

         org.omg.CORBA.Object objref1=orb.resolve_initial_references(\"RootPOA\");
         POA rootpoa=POAHelper.narrow(objref1);
         rootpoa.the_POAManager().activate();

         serverimpl serverobj=new serverimpl();
         serverobj.setorb(orb);
         org.omg.CORBA.Object objref2=rootpoa.servant_to_reference(serverobj);
         revsent href=revsentHelper.narrow(objref2);

         org.omg.CORBA.Object objref3= orb.resolve_initial_references(\"NameService\");
         NamingContextExt ncref=NamingContextExtHelper.narrow(objref3);
         String pathname=\"revsent\";
         NameComponent path[]=ncref.to_name(pathname);
         ncref.rebind(path,href);

         System.out.println(\"server ready and waiting...\");

         orb.run();

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

}


// OUTPUT

E:\\DIPI1\\corba prgs\\revsent>java revsent_client -ORBInitialPort 1050 -ORBInitialHost a

Enter string you want to send to server :
hi this is the test of reversing a string by its words

String sent to server : hi this is the test of reversing a string by its words

String recvd from server is as below:
words its by string a reversing of test the is this hi

    Related Post:
  1. Program that reads and writes random access file

  2. Program to determine the sum of the following harmonic series for a given value of n

  3. Program to read rollno, marks of sub1,sub2 and sub3 and on basis of that display result

  4. Program to show some properties of StringBuffer object

  5. Program of creating a file using text fields in windows

  6. Program to show an example of using user-defined package in a program

  7. An applet program of showing new document using showDocument(URL) method

  8. Program to show an example of creating Character Arrays from String objects

  9. Program to show the use of Conditional OR Operator (||) in If Statements

  10. Program which simulate the dictionary in java

  11. File Handling- JAVA

  12. Program of date server and client

  13. Application which takes your marks of six subjects from the client side and displays the percentage that you have obtained

  14. An applet program showing Clicked Event on canvas

  15. RMI based application for login validation based on data saved in text file stored on the server and will display appropriate message to the client..

  16. RMI servlet program to display message

  17. Define an array of ten String elements each containing an arbitrary string of the form “month/day/year”

  18. Program for calculating area of a circle on server side,when a client sends request along with given radius and then displaying result on client side

  19. Program to show the use of Bitwise Operator (~) Complement

  20. Program to show an example of overloading constructors in a class to initialize its data members