Developed by Y. Daniel Liang using Java Servlets (Current time is Sat Nov 21 19:07:44 EST 2009)

The questions are to accompany Introduction to Java Programming, 4E by Y. Daniel Liang. Please report errors to y.daniel.liang@gmail.com.

Introduction to Java Programming, 4E has been superseded by Introduction to Java Programming, 5E.

Chapter 14: Internationalization

Section 14.2 The Locale Class
1   How do you set a button jbt's text to a character with the Unicode 13AE?

A. jbt.setText("13AE");
B. jbt.setText("\13AE");
C. jbt.setText("\u13AE");
D. jbt.setText("/u13AE");
E. jbt.setText('\u13AE');

2   How do you create a locale for the United States?

A. new Locale("en", "US");
B. new Locale("US", "en");
C. Locale.US;
D. a and c;

3   Which of the following method is defined in the Locale class?

A. getLanguage();
B. getCountry();
C. getVariant();
D. all the above;

4   Which of the following method is correct to obtain the available locales in the classes Calendar, Collator, DateFormat, and NumberFormat?

A. getLocales();
B. getAllLocales();
C. getAvailableLocales();
D. None of the above;

Section 14.3 Processing Date and Time
5   Which of the following set of code lines displays the current time in locale sensitive format?

A.  
GregorianCalendar gcal = new GregorianCalendar();
System.out.println(gcal.toString());

B.  
Date d = new Date();
System.out.println(d.toString());

C.  
GregorianCalendar gcal = new 
GregorianCalendar(new TimeZone("CST"));
System.out.println(gcal.toString());

D.  
GregorianCalendar gcal = new GregorianCalendar();
DateFormat myFormat = DateFormat.getDateTimeInstance();
myFormat.setTimeZone(TimeZone.getTimeZone("CST"));
System.out.println(myFormat.format(gcal.getTime()));



6   Which of the following code is correct to obtain hour from a Calendar object cal?

A. cal.getHour();
B. cal.hour();
C. cal.get(Hour);
D. cal.get(Calendar.HOUR);

7   Which of the following code is correct to set a time zone in a Calendar object?

A. cal.timeZone("CST");
B. cal.setTimeZone("CST");
C. cal.getTimeZone();
D. cal.get(Calendar.HOUR);

8   Which of the following are the valid date and time format?

A. SHORT;
B. MEDIUM;
C. LONG;
D. FULL;
E. All the above;

Section 14.4 Formatting Numbers
9   Which of the following code is correct to create an instance for formatting numbers?

A. NumberFormat.getPercentInstance(locale);
B. NumberFormat.getNumberInstance(locale);
C. NumberFormat.getInstance(locale);
D. None of the above;

Section 14.5 Resource Bundles (Optional)
10   Which of the following code is correct to create an instance of ResourceBundle?

A. ResourceBundle.getBundle();
B. ResourceBundle.getBundle(locale);
C. ResourceBundle.getBundle(resourcefilename);
D. None of the above;

11   Which of the following code displays the numbers with at least two digits before and after the decimal point?
A.
NumberFormat numberForm = NumberFormat.getNumberInstance();
DecimalFormat df = (DecimalFormat)numberForm;
df.applyPattern("00.00");
B.
NumberFormat numberForm = NumberFormat.getNumberInstance();
numberForm.setMaximumFractionDigits(2);
numberForm.setMinimumFractionDigits(2);
C.
NumberFormat numberForm = NumberFormat.getNumberInstance();
numberForm.setMaximumFractionDigits(2);

D. a and b.