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 Logical or Boolean Negation i.e. NOT (!)

  2. Develop a RMI based application for addition of two complex numbers

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

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

  5. Program to show the use of some Character Methods

  6. Program to show the use of Increment and Decrement Operators

  7. Program to display bank account

  8. Program that takes a long sentence and a character from the client and count the occurrence of the character in the sentence at the server side

  9. Program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7

  10. Program to display triangle of numbers

  11. Program that enabled applet calculator

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

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

  14. Program to show the use of Break Statement

  15. Servlet which takes input from an HTML client page and calculates and outputs the premium amount

  16. An applet program to display text

  17. Program to compare Strings by compring successive corresponding characters, starting with the first character in each String

  18. Program to display text

  19. Write a program for restaurant

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