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, which creates a three thread. One thread display the numbers from 1 to 5, second thread display the square root of that number etc

  2. Encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time after each word in the sent

  3. Program to show the comparing of Strings for equality

  4. Program for Thread Priority

  5. Program to Display Output in triangular shape

  6. RMI based application, which reads a file with list of marks of student from a client, send it to server and find how many students having distinct

  7. Even no or Prime no?????

  8. Program which creates an Array of character. Make one function with one argument as a character and that function throw a user defined exception

  9. Program to show the use of Nested Loops

  10. Program to read command line arguments

  11. Program to search an element in an array using Linear Search

  12. CORBA program for displaying the date and time of the server machine, client machine and the difference between these two date and time

  13. Program to show an example of getting at characters in a String

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

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

  16. Program to show an example of using a recursive method in a class

  17. An applet program to display text

  18. Program that will read real number from the keyboard and print the following output in one line: small Integer not less The Given Number Largest Int

  19. Pass the marks of 10 students from the client side design a servlet, which takes these marks and returns the number of students who obtained first cls

  20. Program to show an example of Overriding a Base Class Method