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 which will read a string and rewrite it in the alphabetical order

  2. Corba program to Write a Echo server and client with UDP server and client

  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. Even number ,Prime no. ,Factorial of a number

  5. Program to evaluate following investment equation V=P(1+R)^N

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

  7. Program to show an example of using a Non-Static Nested Class

  8. Program to print a string on Standard Output Device

  9. Program to show the use of While Loop

  10. CORBA PROGRAM TO GET THE HTML CODE FROM ANY URL

  11. Program sets up a String variable containing a paragraph of text of your choice. Extract the words from the text and sort them into alphabetical order

  12. Create an interface coversions. Which have the following functions Inchestomillimeters(), hptowatts(),wattstohp(),poundstogram(),gramtopounds()

  13. CORBA based application for addition of two mathematical expressions of the form (ax + by) and displaying the result on client side

  14. Program to show the use of Nested Loops

  15. File handling program to copy characters from one file to another

  16. 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

  17. An applet program of linear sort

  18. 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..

  19. Program to read input from the Standard Input Device

  20. Program to copy the elements of an array into another array in reverse order and print them