By dananourie on Jan 08, 2008
1. Given two objects
BigDecimal type, how do you multiply the two factors to calculate a product in object
three? Answer: D
To generate the product of two variables of
BigDecimal type, use the
multiply() method of
BigDecimal. This was shown in "The Need for
BigDecimal" (July 2007), which also discussed formatting and rounding issues.
2. In order to write the line
System.out.println("Pi = " + PI), what must the import statement be so that the compiler will locate
PI in the
Math class? Answer: C
Use static import statements to tell the compiler about constants and methods you wish to use without explicitly specifying the class they come from. See "Using Static Imports for Constants and Methods" (October 2004) for more information on working with static imports.
3. When using an enhanced
for loop (also known as a
foreach statement), what interface must the element following the colon (:) implement in order for the construct to compile and execute appropriately? Answer: B
The argument must implement the
Iterable interface, which consists of a single method, to get an iterator:
4. When two Swing components overlap in their display area, how do you control which component is drawn on top? Answer: C
Z-order represents the layering of the components on the screen, where x and y coordinates are for horizontal and vertical positioning, respectively. By calling the
setComponentZOrder() method of the
Container for each component that overlaps, you can explicitly control which components are drawn on top of which other components. See "Let There Be Z-Order" tip (January 2005) for additional information on controlling the z-order layering.
5. What is the best way to monitor the progress of image reading when using the Java Image I/O API? Answer: C
Although you can certainly display progress with a
Progress Monitor, the best way to set up notification of such progress is by using a
IIOReadProgressListener. "Monitoring Image I/O Events" (February 2007) covered this notification as well as region-update notifications.