Java Tutorial

 
 
 
 
----------------------------------------------------------------------------------
                    IDL
----------------------------------------------------------------------------------
module CircleApp
{
    interface Circle
    {
        float area(in float val);
        oneway void shutdown();
    };
};

-------------------------------------------------------------------------------------------------
                    Server
-------------------------------------------------------------------------------------------------

import CircleApp.*;
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;

class CircleImpl extends CirclePOA
{
    private ORB orb;

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

    public float area(float val)
    {
        float res = (float)( Math.PI * val * val );
        return res;
    }
    public void shutdown()
    {
        orb.shutdown(false);
    }
}


public class CircleServer
{

    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();

            CircleImpl circleImpl = new CircleImpl();
            circleImpl.setORB(orb); 

            org.omg.CORBA.Object ref = rootpoa.servant_to_reference(circleImpl);
            Circle href = CircleHelper.narrow(ref);

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

            String name = \"Circle\";
            NameComponent path[] = ncRef.to_name( name );
            ncRef.rebind(path, href);

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

            orb.run();
        } 

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

        System.out.println(\"CircleServer Exiting ...\");
    }
}

-------------------------------------------------------------------------------------------------
                    Client
-------------------------------------------------------------------------------------------------

import CircleApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.io.*;

public class CircleClient
{
    public float getValue() throws IOException
    {
        float val = 0;
        try
        {
            System.out.print(\"Enter the value : \");
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String s=br.readLine();
            val = Float.parseFloat (s);
        }
        catch (IOException e)
        {
            System.out.println(e);
        }
        return val;
    }

    public static void main(String args[])
    {
        Circle circleImpl=null;
        CircleClient cc = new CircleClient();

        try
        {
            ORB orb = ORB.init(args, null);
            org.omg.CORBA.Object objRef = orb.resolve_initial_references(\"NameService\");
            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
            String name = \"Circle\";
            circleImpl = CircleHelper.narrow(ncRef.resolve_str(name));

            float val = 0, res = 0;
            val = cc.getValue();
            res=circleImpl.area(val);
            System.out.println(\"Result : \" + res);

            circleImpl.shutdown();

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

}

-------------------------------------------------------------------------------------------------
                    Output
-------------------------------------------------------------------------------------------------

Enter the value : 2
Result : 12.566371

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

  2. RMI program of count server and client

  3. GUI application in java, which enter the details of a student and on the submit display the details of the student

  4. An applet program to find maximum of three numbers using textField

  5. Program to read the price of an item in decimal form (like 75.95) and print the output in paise (like 7595 paise).

  6. An applet program to draw concentric circle in center of the canvas

  7. Program of bubble sort

  8. Biological Sequence Allignment Using Dynamic Programing

  9. Develop a CORBA based application for addition of two complex numbers and displaying the result on client side

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

  11. Program to generate SQUARE ROOT table

  12. An applet program to draw circle in center of the canvas

  13. Program to show an example of getting at characters in a String

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

  15. Program to find a factorial of a given number

  16. An applet program of showing new document using showDocument(URL) method

  17. Program to show the use of Break Statement

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

  19. Program in CORBA which takes a long sentence from client (at least 7 words), passes to the server, server separates out each word and sends back

  20. CORBA program for displaying the date and time of the server machine, client machine and the difference between these two date and time