Java Tutorial

 
 
 
 
// Addexpr.idl

module AddExprApp
{
        struct Expr
        {
                long Xcord;
                long Ycord;
        };
        interface AddExpr
        {
                Expr addition(in Expr one, in Expr two);
        };
};


// Addexprclient.java

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

import java.io.*;

public class AddExprClient
{
    static AddExpr addExprImpl;
    public static void main(String args[]) throws IOException
    {
      try
      {
        // create and initialize the ORB
            ORB orb = ORB.init(args, null);

        // get the root naming context
        org.omg.CORBA.Object objRef = 
        orb.resolve_initial_references(\"NameService\");
        // Use NamingContextExt instead of NamingContext. This is 
        // part of the Interoperable naming Service.  
        NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

        // resolve the Object Reference in Naming
        String name = \"AddExpr\";
        addExprImpl = AddExprHelper.narrow(ncRef.resolve_str(name));

    System.out.println(\"Obtained a handle on the server object : \" + addExprImpl);

                        Expr one,two;
                        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                        System.out.print(\"Enter first expression X-cord : \");
                        int x=Integer.parseInt(br.readLine());
                        System.out.print(\"Enter first expression Y-cord : \");
                        int y=Integer.parseInt(br.readLine());
                        one=new Expr(x,y);

                        System.out.print(\"Enter second expression X-cord : \");
                        x=Integer.parseInt(br.readLine());
                        System.out.print(\"Enter second expression Y-cord : \");
                        y=Integer.parseInt(br.readLine());
                        two=new Expr(x,y);

                        one=addExprImpl.addition(one,two);

                        System.out.println(\"result of addition is \" + one.Xcord +
                                \"X + (\" + one.Ycord + \"Y)\");

        }
      catch (Exception e) 
      {
          System.out.println(\"ERROR : \" + e) ;
            e.printStackTrace(System.out);
          }
    }
}


// AddexprServer.java

import AddExprApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;

import java.util.Properties;
import java.util.StringTokenizer;

class AddExprImpl extends AddExprPOA {
  private ORB orb;

  public void setORB(ORB orb_val) {
    orb = orb_val; 
  }

        public Expr addition (Expr one, Expr two)
        {
                return new Expr(one.Xcord+two.Xcord,one.Ycord+two.Ycord);
        }
}


public class AddExprServer {

  public static void main(String args[]) {
    try{
      // create and initialize the ORB
      ORB orb = ORB.init(args, null);

      // get reference to rootpoa & activate the POAManager
      POA rootpoa = POAHelper.narrow(orb.resolve_initial_references(\"RootPOA\"));
      rootpoa.the_POAManager().activate();

      // create servant and register it with the ORB
      AddExprImpl addExprImpl = new AddExprImpl();
      addExprImpl.setORB(orb); 

      // get object reference from the servant
      org.omg.CORBA.Object ref = rootpoa.servant_to_reference(addExprImpl);
      AddExpr href = AddExprHelper.narrow(ref);

      // get the root naming context
      // NameService invokes the name service
      org.omg.CORBA.Object objRef =
          orb.resolve_initial_references(\"NameService\");
      // Use NamingContextExt which is part of the Interoperable
      // Naming Service (INS) specification.
      NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

      // bind the Object Reference in Naming
      String name = \"AddExpr\";
      NameComponent path[] = ncRef.to_name( name );
      ncRef.rebind(path, href);

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

      // wait for invocations from clients
      orb.run();
    } 

      catch (Exception e) {
        System.err.println(\"ERROR: \" + e);
        e.printStackTrace(System.out);
      }

      System.out.println(\"AddExprServer Exiting ...\");

  }
}


// OUTPUT

Enter first expression X-cord : 12

Enter first expression Y-cord : 23

Enter second expression X-cord : 4

Enter second expression Y-cord : 5

result of addition is (16x+28y)

    Related Post:
  1. Program to show the use of If-Else Statement

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

  3. Program to calculate the frequency for different values of C starting from 0.01 to 0.1 in steps of 0.01

  4. Develop a game application in CORBA for which the player will guess a number between 1 to 100, which will be compared to the random number generated b

  5. Program to show the use of some Character Methods

  6. An applet program to display sum of two number of textField

  7. Program of storing and retrieving integers using data streams on a single file

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

  9. Program which simulate the dictionary in java

  10. Program of linear search

  11. Program to display reverse $ tree

  12. Program to show the use of some Math Methods

  13. Word list program that reads a text file and makes an alphabetical list of all the words in that file. The list of words is output to another file

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

  15. An applet of displaying simple moving banner

  16. Program of concatenating and Buffering files

  17. Program to read input from the Standard Input Device

  18. Program to represent a bank account

  19. Program to display following things on the client machine a)date and time of the server machine b)date and time of the client machine and difference

  20. Program to show an example of creating a String object from a StringBuffer Object