IDL to Java Mapping - Quiz Explanation

The correct answers are indicated below, along with text that explains the correct answers.
 
1. What would be the package name for module bar in the following IDL definition? Please select the best answer.
  A. package foo.bar;
  B. package org.omg.CORBA.bar;
  C. package bar
  D. package org.omg.CORBA.foo.bar
  The correct answer is A. bar is declared inside foo so the structure is maintained by declaring bar as a subpackage of foo. Answers B and D are incorrect because the org.omg.CORBA package is only for core CORBA classes. Classes generated for your projects should go into a package according to your company’s naming conventions. Therefore the IDL compiler does not make any assumptions about the package prefix to foo. E is incorrect because the IDL compiler tries to keep the names as close to the IDL as possible.

2. To what Java type does an IDL long map? Please select the best answer.
  A. java.lang.Integer
  B. int
  C. java.lang.Long
  D. long
  The correct answer is B.
Answers A and C are incorrect because the mapping tries to map to Java primitive types, not Java classes, wherever possible.
D is incorrect because a Java int is 32 bits and a Java long is 64 bits, but an IDL long is only 32 bits. IDL, like C, differentiates between two major lengths of integers short and long. In C, int is the same as one of the two lengths depending on the word size of the machine for which it is compiled. IDL removes this ambiguity by dropping the type int. Java however, solves the ambiguity by making a distinction between three different integer lengths.

3. What is the difference between the IDL types char and wchar? To what Java type do they each map? Please select the best answer.
  A. There is no difference, they both map to a Java char.
  B. Char is a byte and so maps to a Java byte. wchar is a Unicode char and so maps to a Java char.
  C. Char is a byte, whereas wchar is a Unicode char, but they both map to a Java char.
  D. Char is a character data type , whereas wchar is a wrapped char.
  The correct answer is C.
Even though the length of the data values differs and the size of an IDL char does not match the size of a Java char, the semantics of an IDL char and a Java char are the same. This is more important for conversion than exact data size. B is incorrect because converting an IDL char to a Java byte would turn the value into a signed integer from -127 to 127, losing the idea that it represents a character. A is incorrect because there is a difference between the two IDL types.