public void run() {
System.out.println("Timer task executed.");
}
}class TTest {
public static void main(String args[]) {
MyTimerTask myTask = new MyTimerTask();
Timer myTimer = new Timer();/* Set an initial delay of 1 second,
then repeat every half second.
*/
myTimer.schedule(myTask, 1000, 500);try {
Thread.sleep(5000);
} catch (InterruptedException exc) {}myTimer.cancel();
}
}Currency
TheCurrencyclass encapsulates information about a currency. It defines no constructors. The
methods supported byCurrencyare shown in Table 18-10. The following program
demonstratesCurrency:// Demonstrate Currency.
import java.util.*;class CurDemo {
public static void main(String args[]) {
Currency c;c = Currency.getInstance(Locale.US);System.out.println("Symbol: " + c.getSymbol());
System.out.println("Default fractional digits: " +
c.getDefaultFractionDigits());
}
}The output is shown here:Symbol: $
Default fractional digits: 2524 Part II: The Java Library