OOPortal 





Java Programming  «Prev  Next»
Lesson 5 Constants and typedefs
Objective Describe the mapping of IDL constants and typedefs in Java.

Corba Constants and Typedefs

Constants and typedefs are probably the simplest constructs in IDL.
A constant is a primitive value bound to a name. A typedef is an aliasing of a type name to allow better semantic description in the IDL definition as well as to provide a little bit of change management functionality.

const

If you define a constant (const) within an IDL interface, it is mapped as a public static final variable in the generated Java interface. However, constants are more often defined within a module scope rather than within an interface. In this case, there is no Java class or interface in which a static variable can be defined. If you define a constant in a module, a class is generated for that variable in the package generated for that module. Each constant defined gets its very own class, and the name of that class is the name of the constant. The value is assigned to a public static final variable named value.
The Slide Show below shows the IDL interface const mapping to the value public static final variable in Java:


Mapped Constant Typedef

typedef

The design philosophy with which Java was created specifically excludes type aliasing. Under Java, IDL typedefs mostly disappear. You are expected to use the underlying element type rather than the alias name. A typedef declaration does not completely disappear, though. The helper classes are still created for the type name even though a new class is not created for it. In the next lesson, you will learn how to describe the mapping of methods in IDL interfaces in Java and how to execute remote methods.

IDL Java Mapping - Quiz

Click the Quiz link below to take a quiz on IDL-to-Java mapping.
IDL Java Mapping - Quiz