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. Servlet which takes input from an HTML client page and calculates and outputs the premium amount

  2. Program which will read a string and rewrite it in the alphabetical order

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

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

  5. RMI based application for login validation based on data saved in text file stored on the server and will display appropriate message to the client..

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

  7. Program that reads and writes random access file

  8. Corba program of reverse string

  9. Program to show some properties of StringBuffer object

  10. Program to show an example of modifying String objects

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

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

  13. Program to show an example of using a recursive method in a class

  14. Program of date server and client

  15. Program to show an example of extracting subStrings from a String

  16. Program to read input from the Standard Input Device

  17. File handling program to copy characters from one file to another

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

  19. Program to display text

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