Java Tutorial

 
 
 
 
// ComplexNumber.idl

module Ex3Module
{
    interface ComplexNumber
    {
        void setFirstNumber(in long long real , in long long imaginary) ;
        void setSecondNumber(in long long real , in long long imaginary) ;
        void doSum() ;
        long long getReal() ;
        long long getImaginary() ;
    } ;
} ;


// ComplexNumberImpl.java

import Ex3Module.ComplexNumberPOA ;

class ComplexNumberImpl extends ComplexNumberPOA
{
    long FirstReal , FirstImaginary ;
    long SecondReal , SecondImaginary ;
    long SumReal , SumImaginary ;

    public void setFirstNumber(long real , long imaginary)
    {
        FirstReal = real ;
        FirstImaginary = imaginary ;
    }

    public void setSecondNumber(long real , long imaginary)
    {
        SecondReal = real ;
        SecondImaginary = imaginary ;
    }    

    public void doSum()
    {
        SumReal = FirstReal + SecondReal ;
        SumImaginary = FirstImaginary + SecondImaginary ;
    }

    public long getReal()
    {
        return SumReal ;
    }

    public long getImaginary()
    {
        return SumImaginary ;
    }
}


// ComplexNumberClient.java

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

class ComplexNumberClient
{
    public static void main(String [] args)    
    {
        ComplexNumber cNumber = null ;

        try
        {
            org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);

            org.omg.CORBA.Object objRef = orb.resolve_initial_references(\"NameService\");
            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);    

            String name = \"ComplexNumber\" ;

            cNumber = ComplexNumberHelper.narrow(ncRef.resolve_str(name));

            cNumber.setFirstNumber(9 , 4) ;
            cNumber.setSecondNumber(8 , 2) ;
            cNumber.doSum() ;

            System.out.println(\"The sum of two complexnumber is : \" + cNumber.getReal() + \" + \" + cNumber.getImaginary() + \"i\") ;


        }
        catch(Exception e)
        {
            e.printStackTrace() ;
        }
    }
}


// ComplexNumberServer.java

import Ex3Module.ComplexNumber ;
import org.omg.CosNaming.* ;
import org.omg.CosNaming.NamingContextPackage.* ;
import org.omg.PortableServer.* ;

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

            POA rootPOA = POAHelper.narrow(orb.resolve_initial_references(\"RootPOA\"));

            rootPOA.the_POAManager().activate();

            ComplexNumberImpl cNumber = new ComplexNumberImpl() ;

            org.omg.CORBA.Object ref = rootPOA.servant_to_reference(cNumber) ;

            System.out.println(\"Step1\");
            ComplexNumber h_ref = Ex3Module.ComplexNumberHelper.narrow(ref);

            System.out.println(\"Step2\");
            org.omg.CORBA.Object objRef = orb.resolve_initial_references(\"NameService\");

            System.out.println(\"Step3\");
            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

            System.out.println(\"Step4\");
            String name = \"ComplexNumber\";

            NameComponent path[] = ncRef.to_name(name);
            ncRef.rebind(path,h_ref);

            System.out.println(\"ComplexNumber Server reading and waiting....\");
            orb.run();

        }
        catch(Exception e)        
        {
            e.printStackTrace() ;
        }
    }
}

    Related Post:
  1. File handling program to count number of characters in a file

  2. Simple Applet which will show life cycle of an Applet

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

  4. An applet program to display text

  5. An applet program that concatenates two string entered in TextField

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

  7. Develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side, executed on server

  8. An applet program that displays random dot

  9. An applet program to give demo of getDocumentBase() and getCodeBase() methods

  10. Program to read the table elements into a two-dimensional array temperature

  11. Program to Display Output in triangular shape

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

  13. RMI application for counting factorial of a given number.

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

  15. Define an array of ten String elements each containing an arbitrary string of the form “month/day/year”

  16. Program to read bytes from a file

  17. Program to show an example of Polymorphism

  18. RMI application for getting the final total price of the shopping list with some of the following items and quantities chosen by the user

  19. An applet program to draw Polygon Graph with given data

  20. Program to declare, initialize and print a StringBuffer object