Interface Definition Language IDL Hello World Tutorial with Java and C++

In this tutorial, we will show how to write a simple IDL file and compile for Java and C++.

IDL is a specification language used to describe an interface in a language-independent way to enable communication between software components or objects which do not share one language. For example, between those written in C++ to Java.

We will be using the Addition example being explained for different paradigms (Sockets, RMI…).

1 Open your favorite text editor and create a new file named Calcs.idl

2 Type the following code within the created Calcs.idl


module Calcs
  // Interface for a Addition
  interface Addition {
    attribute short a;
    attribute short b;
    // an exception that can be raised
    exception invalidNumber { string why ;};

 // public method
    short add(in short c, in short d)raises (invalidNumber) ;
  } ;
} ;

module : is for creating a namespace ( equivalent of a package in Java).
attribute : is a special keyword used to map a variable to Setter and Getter method ( set and get )
short : is a 16-bit basic data type
exception invalidNumber { string why ;}; : Defining an exception to indicate an occurrence of an error.
short add(in short a, in short b)raises (invalidNumber) ; : This is method/procedure which returns a short. Takes two arguments of type short.

3 For java users, you need to compile using the idlj :

idlj Calcs.idl

Once you have compiled using the IDLJ, You would get the necessary files to get your Java Server or Client going with CORBA

More detailed tutorial of how to use CORBA within Java can be found here


4 In case you are on Linux, it is easy to get things done. You need to install the ORB compiler (ubuntu):

sudo apt install omniidl

5 You need to compile the IDL now:

omniidl -bcxx Calcs.idl


For Windows users, You can download the TAO from the Aceorb website at:

To compile, use the following command :

tao_idl -GI Calcs.idl