Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

January 2008 Core Java Tech Tips Quiz

 

by John Zukowski

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 one and two of BigDecimal type, how do you multiply the two factors to calculate a product in object three?

a. BigDecimal three = one * two;

b. BigDecimal three = one.*(two);

c. BigDecimal three = one.times(two);

d.

BigDecimal three = one.multiply(two);<code><br>
</p>
<p>
2. In order to write the line <code>System.out.println("Pi = " + PI)
, what must the import statement be so that the compiler will locate PI in the Math class?

a. import java.lang.Math;

b. import java.lang.Math.PI;

c. import static java.lang.Math.PI;

d. 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?

a. Enumeration

b. Iterable

c. Iterator

d. Collection

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.