Getting Started: Hello World


Introductory information about the tutorial (in this file) includes:

Note: The Hello World example is provided with pre-built stub and skeleton files. However, to generate these files yourself and take full advantage of this Tutorial, you will need to download the idltojava compiler.

Hello World Program Overview

This tutorial teaches the basic tasks in building a CORBA distributed application using Java IDL. You will build the classic "Hello World" program as a distributed application, with both applet and application clients.The Hello World program has a single operation that returns a string to be printed. Its basic function is illustrated below:


Operation of the Distributed Hello World Program

  1. The client (applet or application) invokes the sayHello() operation of the HelloServer.
  2. The ORB transfers that invocation to the servant object registered for that IDL interface.
  3. The servant's sayHello() method runs, returning a Java String.
  4. The ORB transfers that String back to the client.
  5. The client prints the value of the String.

Tutorial Overview

Despite its simple design, the Hello World program lets you learn and experiment with all the tasks required to develop almost any CORBA program that uses static invocation.

Each lesson has a directory in the docs/guide/idl/tutorial directory of your JDK installation containing valid source files and compiled class files needed for completing the lesson. Although the lessons are designed to build upon one another, you can do the lessons in any order you want by using the files provided.

The lessons in this tutorial are listed below.

Previewing Hello World

You can run the Hello World application before you work through the tutorial. Follow the instructions listed for your operating system:

Building Hello World under the Solaris Operating System

The source code for the Hello World example is located in [Path_to_JDK]/docs/guide/idl/examples/Hello. The following instructions assume you can use port 1050 for the Java IDL name server. Substitute a different port if necessary. (Note that to use a port below 1024, you need root access on Unix machines and administrator privileges on Wintel machines.) Substitute the completely-qualified path to your JDK installation for [Path_to_JDK]

Note: Steps 2 and 3 require you to have downloaded and installed the idltojava compiler.

  1. Change to the example directory:
    cd [Path_to_JDK]/docs/guide/examples/hello
  2. Make certain that the idltojava compiler ([Path_to_JDK]/bin) and the Java binaries are included in your path environment variable.

  3. Compile the IDL file with idltojava to create stubs and skeletons.
    Note: idltojava is hard-coded to use a default preprocessor. On Solaris machines, it uses the path /usr/ccs/lib/cpp when looking for the preprocessor. You can change the preprocessor that idltojava uses by setting two environment variables: CPP and CPARGS. Set CPP to the full pathname of the preprocessor you want to use. Set CPARGS to the complete list of arguments to be passed to the preprocessor. You can also turn off the preprocessor by adding -fno-cpp to the idltojava command line. More information is available in the idltojava reference page that is downloaded with the idltojava compiler.
    idltojava Hello.idl
  4. Compile the Java files, including the stubs and skeletons:
    javac *.java HelloApp/*.java
    
  5. Start the Java IDL name server:
    tnameserv -ORBInitialPort 1050 &
    

    You will see something like the following:

    Initial Naming Context:
    IOR:000000000000002849444c3a6f6d672e6f72672f436f734e616d696e672f4e616d696e67436f6e746578743a312e3000000000010000000000000034000100000000000974687572626c6967000086760000001cafabcafe0000000233de2f5c00000000000000080000000000000000
    TransientNameServer: setting port for initial object references to: 1050
    

    The server runs in the background; you see no more evidence of it until you run the client program.

  6. Start the Hello server:
    java HelloServer -ORBInitialPort 1050 &
  7. Run the Hello application client:
    java HelloClient  -ORBInitialPort 1050

    The string prints to the command line:

    Hello world!!

The name server and the Hello World server, like many CORBA servers, run until you explicitly stop them. To avoid having many servers running, kill the server processes before proceeding to Lesson One.

Building Hello World under the Windows Operating System

Using Windows 95 or Windows NT, the source code for the Hello World example is located in [Path_to_JDK]\docs\guide\idl\examples\Hello. The following instructions assume you can use port 1050 for the Java IDL name server. Substitute a different port if necessary. Substitute the completely-qualified path to your JDK installation for [Path_to_JDK]

Note: Steps 2 and 3 require you to have downloaded and installed the idltojava compiler.

  1. Change to the example directory:
    cd [Path_to_JDK]\docs\guide\idl\examples\hello
  2. Make certain that the idltojava compiler ([Path_to_JDK]\bin) and the Java binaries are included in your path environment variable.

  3. Translate the IDL file to Java with the idltojava compiler to create stubs and skeletons.
    Note: idltojava is hard-coded to use a default preprocessor. On Windows machines, it uses the MS Visual C++ preprocessor. You can change the preprocessor that idltojava uses by setting two environment variables: CPP and CPARGS. Set CPP to the full pathname of the preprocessor you want to use. Set CPARGS to the complete list of arguments to be passed to the preprocessor. You can also turn off the preprocessor by adding -fno-cpp to the idltojava command line. More information is available in the idltojava reference page that is downloaded with the idltojava compiler.
    idltojava Hello.idl
  4. Compile the Java files, including the stubs and skeletons:
    javac *.java HelloApp\*.java
  5. Start the Java IDL name server:
    tnameserv -ORBInitialPort 1050

    The server runs in the background; you see no more evidence of it until you run the client program.

  6. Start the Hello server:
    java HelloServer -ORBInitialPort 1050
  7. Run the Hello application client:
    java HelloClient -ORBInitialPort 1050

    The string prints to the command line:

    Hello world!!

The name server and the Hello World server, like many CORBA servers, run until you explicitly stop them. To avoid having many servers running, kill the server processes before proceeding to Lesson One.

For More Information

Although concepts are explained as they are introduced in the tutorial, you will find a discussion in greater depth and useful background information in the Fundamentals section. In addition, new terms are linked to their definitions throughout the tutorial.

Also, CORBA for Beginnners from the Object Management Group provides another source of basic CORBA information.


Lesson One
Home

Copyright © 1996-1998 Sun Microsystems, Inc., 2550 Garcia Ave., Mtn. View, CA. 94043-1100 USA., All rights reserved.