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 enabled applet that takes name of the user. Server returns back the number in uppercase clubbed with “HELLO” and display it on applet

  2. Write a class whose objects holds a current value and have a method to add that value, printing the new value

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

  4. Program to show the use of the Continue Statement

  5. Program of insertion sort

  6. Program to check the start and end of a String

  7. Program to delete mth element from an input string

  8. An applet program to display Vertical Color Bar

  9. Program to show the use of Switch Statement for the same statement for several different case labels

  10. Program to change characters in a StringBuffer objects and to reverse its contents

  11. Program to show the use of Conditional AND Operator (&&) in If Statements

  12. Program to show the use of Break Statement

  13. Program to declare and initialize Integer variables and print them on the Standard Output Device

  14. Corba program of UDP client server application which sends the news to the client. Server takes the news from the NewsDataFile located at the server

  15. Program that enabled applet calculator

  16. Corba program of reverse string

  17. Program to show the use of Nested Loops

  18. Program to declare, initialize and print an array of characters

  19. Program that accepts a shopping list of five items from the command line and stores them in vector

  20. Program to append a StringBuffer by StringBuffer, String objects and other Basic Data Types