January 2008 Core Java Tech Tips Quiz
By dananourie on Jan 08, 2008
We've made it through another year, and it's time for another tech tips quiz. The last two -- June 2006 and September 2005 -- were popular refreshers of past tips and tricks. Here are another five questions for you. Don't look too far ahead, as the answers are at the end of this entry.
1. Given two objects
BigDecimal type, how do you multiply the two factors to calculate a product in object
BigDecimal three = one \* two;
BigDecimal three = one.\*(two);
BigDecimal three = one.times(two);
BigDecimal three = one.multiply(two);
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
import static java.lang.Math.PI;
import final java.lang.Math.PI;
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?
4. When two Swing components overlap in their display area, how do you control which component is drawn on top?
a. The component added to the container first is drawn on top.
b. The component added to the container last is drawn on top.
c. You call the
setComponentZOrder() method of the container.
d. You call the
setComponentZOrder() method for each component.
5. What is the best way to monitor the progress of image reading when using the Java Image I/O API?
a. Create a
FilteredReader subclass to count the bytes.
b. Attach a
ProgressMonitorListener to the
ImageReader to report progress.
c. Attach an
IIOReadProgressListener to the
ImageReader for progress reporting.
d. Register a
Runnable with the
ImageReader and tell it how frequently to execute.
Check your answers here.