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. Application which takes your marks of six subjects from the client side and displays the percentage that you have obtained

  2. Program to show an example of Overriding a Base Class Method

  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 of linear search

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

  6. Corba program of UDP client server application which sends the news to the client. Server takes the news from the NewsDataFile located at the server

  7. Program to show the use of For Loop

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

  9. Program to show an example of using a Static Nested Class outside the Top-Level Class

  10. Even number ,Prime no. ,Factorial of a number

  11. An applet program to draw different shapes

  12. Program to show the use of Do-While Loop

  13. Program to display bank account

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

  15. Program to determine the sum of the following harmonic series for a given value of n

  16. Program to show insertion of StringBuffer, String objects and other Basic Data Types into a StringBuffer object

  17. Program to show an example of creating a class and using its object

  18. Corba program to encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time.

  19. Program that reads and writes random access file

  20. Program of concatenating and Buffering files