O'Reilly logo

Java Enterprise in a Nutshell, Third Edition by William Crawford, Jim Farley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Constants and Literals

Literals are explicit values inserted into IDL code. Sometimes literals are used to specify a default value for interface attributes or to declare the value for a constant. Literals can be Boolean (true or false), numeric (integer, floating point, or fixed point), or character-based (a single character or a string).

Literals are most often used in IDL to initialize the value of constants . Constants are named variables that are restricted from being modified after being initialized. In IDL, a constant is declared using the syntax:

// IDL
const <type spec> <identifier> = <value>;

where < type spec > is any valid basic data type or declared interface type, < identifier > is any valid IDL identifier, and < value > is any IDL expression that evaluates to a literal value. The initialization expression can be a simple literal or it can be a complex expression combining multiple literals using logical or mathematical operators. You could declare a few useful numeric constants as follows, for example:

// IDL
const float half = 1 / 2;
const float quarter = 1 / 4;

Most of the operators present in C/C++, such as addition (+), subtraction (-), multiplication (*), and the logical and bitwise operators (|, &, ^, ||, &&, etc.) are supported by IDL.

Mapping Constants to Java

If an IDL constant is declared within an interface definition, then the constant is mapped to a public static final static member on the corresponding Java interface.

If the IDL constant is declared outside of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required