Java Tutorial

 
 
 
 
----------------------------------------------------------------------------------
                    IDL
----------------------------------------------------------------------------------
module MyString
{
   interface StringOp
   {
    string revstr(in string strMyString);
    oneway void shutdown();
   };
};

-------------------------------------------------------------------------------------------------
                    Server
-------------------------------------------------------------------------------------------------

import MyString.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import java.util.Properties;

class stringImpl extends StringOpPOA
{
    private ORB orb;
    public void setORB(ORB orb_val)
    {
        orb = orb_val;
    }
    public String revstr(String strMyString)
    {
        String strMyString1;
        StringBuffer temp = new StringBuffer(strMyString);
        temp.reverse();
        strMyString1 = temp.toString();
        if((strMyString.equals(strMyString1)) == true)
        {
            return(\"Palindrom\");
        }
        else
        {
            return(\"NotPalindrom\");
        }
    }
    public void shutdown()
    {
        orb.shutdown(false);
    }
}

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

            POA rootpoa = POAHelper.narrow(orb.resolve_initial_references(\"RootPoa\"));

            rootpoa.the_POAManager().activate();

            stringImpl objString = new stringImpl();

            objString.setORB(orb);

            org.omg.CORBA.Object ref = rootpoa.servant_to_reference(objString);
            StringOp href = StringOpHelper.narrow(ref);

            org.omg.CORBA.Object objRef = orb.resolve_initial_references(\"NameService\");

            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

            NameComponent path[] = ncRef.to_name(\"calc\");
            ncRef.rebind(path,href);

            System.out.println(\"Server ready\");

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

-------------------------------------------------------------------------------------------------
                    Client
-------------------------------------------------------------------------------------------------

import MyString.*;
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;

class calcClient
{
    static StringOp stringImpl;
    public static void connect(ORB objOrb, org.omg.CORBA.Object objRef,NamingContextExt ncRef)
    {
        try
        {

            objRef = objOrb.resolve_initial_references(\"NameService\");
            ncRef = NamingContextExtHelper.narrow(objRef);
            stringImpl = StringOpHelper.narrow(ncRef.resolve_str(\"calc\"));
        }
        catch(Exception e)
        {
            System.out.println(e);
            e.printStackTrace();
        }

    }
    public static void main(String args[])
    {
        ORB objOrb=ORB.init(args, null);;
        org.omg.CORBA.Object objRef=null;
        NamingContextExt ncRef=null;
        connect(objOrb,objRef,ncRef);
        String s1 = \"Vidyadhar\",s2;
        s2 = stringImpl.revstr(s1);
        System.out.println(\"Original String is :==> \" + s1);
        System.out.println(\"Ans is :==> \" + s2);

        String s3 = \"nayan\",s4;
        s4 = stringImpl.revstr(s3);
        System.out.println(\"original String is :==> \" + s3);
        System.out.println(\"Ans is :==> \" + s4);

    }
}

-------------------------------------------------------------------------------------------------
                    Output
-------------------------------------------------------------------------------------------------

Original String is :==> Vidyadhar
Ans is :==> NotPalindrom

Original String is :==> nayan
Ans is :==> Palindrom

    Related Post:
  1. Program to show the use of some Character Methods

  2. Program to read command line arguments

  3. Do the following for the Array Insert the element in the array,delete an element from the array,search for a particular element Create multiple thread

  4. Program to read bytes from a file

  5. File Handling- JAVA

  6. Program that demonstrates type casting

  7. Program to show an example of Driving and using a Class

  8. Program to show the use of Comparison operator (==) for comparing Strings

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

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

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

  12. Program to show the comparing of Strings for equality

  13. Program that accepts a shopping list of items from the command line and stores them in a vector. Also provide facility to perform operation

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

  15. Program to show an example of using multiple classes in a program

  16. Program to show the use of Switch Statement

  17. Corba program to develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side

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

  19. Program to show the use of Conditional (Ternary) Operator

  20. Program to read the ballots and count the votes cast for each candidate using an array variable count