jobs4timesLogo jobs4timesLogo

Internationalization

Q: 01 Given:

11. String test = "This is a test"; 
12. String[] tokens = test.split("\s"); 
13. System.out.println(tokens.length); 
What is the result ?
  1. 0
  2. 1
  3. 4
  4. Compilation fails.
  5. An exception is thrown at runtime
Answer: D

Q: 02 Given:

12. System.out.format("Pi is approximately %d.", Math.PI);
What is the result?
  1. Compilation fails.
  2. Pi is approximately 3.
  3. Pi is approximately 3.141593.
  4. An exception is thrown at runtime.
Answer: D

Q: 03 Given:

33. Date d = new Date(0); 
34. String ds = "December 15, 2004"; 
35. // insert code here 
36. try { 
37. d = df.parse(ds); 
38. } 
39. catch(ParseException e) { 
40. System.out.println("Unable to parse " + ds); 
41. } 
42. // insert code here too 
What creates the appropriate DateFormat object and adds a day to the Date object ?
  1. 35. DateFormat df = DateFormat.getDateFormat(); 
    42. d.setTime( (60 * 60 * 24) + d.getTime());
    
  2. 35. DateFormat df = DateFormat.getDateInstance(); 
    42. d.setTime( (1000 * 60 * 60 * 24) + d.getTime());
    
  3. 35. DateFormat df = DateFormat.getDateFormat(); 
    42. d.setLocalTime( (1000*60*60*24) + d.getLocalTime());
    
  4. 35. DateFormat df = DateFormat.getDateInstance(); 
    42. d.setLocalTime( (60 * 60 * 24) + d.getLocalTime());
    
Answer: B

Q: 04 Given:

12. NumberFormat nf = NumberFormat.getInstance(); 
13. nf.setMaximumFractionDigits(4); 
14. nf.setMinimumFractionDigits(2); 
15. String a = nf.format(3.1415926); 
16. String b = nf.format(2);
Which two statements are true about the result if the default locale is Locale.US ? (Choose two.)
  1. The value of b is 2.
  2. The value of a is 3.14.
  3. The value of b is 2.00.
  4. The value of a is 3.141.
  5. The value of a is 3.1415.
  6. The value of a is 3.1416.
  7. The value of b is 2.0000.
Answer: C, F

Q: 05 Click the Task button.

Solution: Pi is Approximately 3.141593 and E is Approximately true

Q: 05 Given:

12. Date date = new Date();
13. df.setLocale(Locale.ITALY);
14. String s = df.format(date);
The variable df is an object of type DateFormat that has been initialized in line 11. What is the result if this code is run on December 14, 2000 ?
  1. The value of s is 14-dic-2004.
  2. The value of s is Dec 14, 2000.
  3. An exception is thrown at runtime.
  4. Compilation fails because of an error in line 13.
Answer: D

Q: 06 Given:

d is a valid, non-null Date object df is a valid, non-null DateFormat object set to the current locale What outputs the current locale's country name and the appropriate version of d's date?
  1. Locale loc = Locale.getLocale();
    System.out.println(loc.getDisplayCountry()+ " " + df.format(d));
    
  2. Locale loc = Locale.getDefault();
    System.out.println(loc.getDisplayCountry()+ " " + df.format(d));
    
  3. Locale loc = Locale.getLocale();
    System.out.println(loc.getDisplayCountry()+ " " + df.setDateFormat(d));
    
  4. Locale loc = Locale.getDefault();
    System.out.println(loc.getDisplayCountry()+ " " + df.setDateFormat(d));
    
Answer: B

Q: 07

Given a valid DateFormat object named df, and
16. Date d = new Date(0L);
17. String ds = "December 15, 2004";
18. // insert code here
What updates d's value with the date represented by ds?
  1.  18. d = df.parse(ds);
  2.  18. d = df.getDate(ds);
  3. 18. try {
    19. d = df.parse(ds);
    20. } catch(ParseException e) { };
    
  4. 18. try {
    19. d = df.getDate(ds);
    20. } catch(ParseException e) { };
    
Answer: C

Q: 08 Click the Task button.

Solution:
Scanner scanner =new Scanner(One, 5 true,3,true,6,7,false"); 
scanner.useDelimiter(" ,"); 
while( scanner.hasNext( ) ) { 
 if ( scanner.hasNextBoolean( ) ){ 
 system.out.print(scanner.nextBoolean( )+" " ); 
 }
 else scanner.Next( ); 
}

Q: 09 Given:

11. double input = 314159.26; 
12. NumberFormat nf = NumberFormat.getInstance(Locale.ITALIAN); 
13. String b; 
14. //insert code here Which code,
inserted at line 14, sets the value of b to 314.159,26 ?
  1. b = nf.parse( input );
  2. b = nf.format( input );
  3. b = nf.equals( input );
  4. b = nf.parseObject( input );
Answer: B

Q: 10 Given:

12. String csv = "Sue,5,true,3"; 
13. Scanner scanner = new Scanner( csv ); 
14. scanner.useDelimiter(","); 
15. int age = scanner.nextInt();
What is the result ?
  1. Compilation fails.
  2. After line 15, the value of age is 5.
  3. After line 15, the value of age is 3.
  4. An exception is thrown at runtime.
Answer: D

Q: 11 Given:

11. String test = "a1b2c3"; 
12. String[] tokens = test.split("\\d"); 
13. for(String s: tokens) System.out.print(s + " "); 
What is the result ?
  1. a b c
  2. 1 2 3
  3. a1b2c3
  4. a1 b2 c3
  5. Compilation fails.
  6. The code runs with no output.
  7. An exception is thrown at runtime.
Answer: A

Question: 12 Given:

14. DateFormat df; 
15. Date date = new Date(); 
16. //insert code here 
17. String s = df.format( date);
Which two, inserted independently at line 16, allow the code to compile ? (Choose two.)
  1. df= new DateFormat();
  2. df= Date.getFormatter();
  3. df= date.getFormatter();
  4. df= date.getDateFormatter();
  5. df= Date.getDateFormatter();
  6. df= DateFormat.getInstance();
  7. df = DateFormat.getDateInstance();
Answer: F, G

Question: 13 Given:

11. String test = "Test A. Test B. Test C."; 
12. // insert code here 
13. String[] result = test.split(regex);
Which regular expression inserted at line 12 will correctly split test into "Test A," "Test B," and "Test C"?
  1. String regex ="";
  2. String regex = " ";
  3. String regex ="*"
  4. String regex = "\\s"
  5. String regex ="\\.\\s*";
  6. String regex = "\\w[ \.] +";
Answer: E

Question: 14 Given:

5. import java.util.Date; 
6. import java.text.DateFormat;
 
21. DateFormat df; 
22. Date date = new Date(); 
23. // insert code here 
24. String s = df.format(date);
Which code fragment, inserted at line 23, allows the code to compile ?
  1. df = new DateFormat();
  2. df = Date.getFormat();
  3. df = date.getFormat();
  4. df = DateFormat.getFormat();
  5. df = DateFormat.getInstance();
Answer: E

15. Given:

import java.util.regex.*; 
class Regex2 { 
 public static void main(String[] args) { 
  Pattern p = Pattern.compile(args[0]); 
  Matcher m = p.matcher(args[1]); 
  boolean b = false; 
 while(b = m.find()) {
  System.out.print(m.start() + m.group()); 
 }
} 
}
And the command line: java Regex2 "\d*" ab34ef What is the result ?
  1. 234
  2. 334
  3. 2334
  4. 0123456
  5. 01234456
  6. 12334567
  7. Compilation fails.
Answer:
  1. E is correct. The \d is looking for digits. The * is a quantifier that looks for 0 to many occurrences of the pattern that precedes it. Because we specified *, the group() method returns empty Strings until consecutive digits are found, so the only time group() returns a value is when it returns 34 when the matcher finds digits starting in position 2. The start() method returns the starting position of the previous match because, again, we said find 0 to many occurrences.
  2. A, B, C, D, E, F, and G are incorrect based on the above.

16. Given:

1. import java.text.*; 
2. class DateOne { 
3. public static void main(String[] args) { 
4. Date d = new Date(1123631685981L); 
5. DateFormat df = new DateFormat(); 
6. System.out.println(df.format(d)); 
7. } 
8. } 
And given that 1123631685981L is the number of milliseconds between Jan. 1, 1970, and sometime on Aug. 9, 2005, what is the result ? (Note: the time of day in option A may vary.)
  1. 8/9/05 5:54 PM
  2. 1123631685981L
  3. An exception is thrown at runtime.
  4. Compilation fails due to a single error in the code.
  5. Compilation fails due to multiple errors in the code.
Answer:
  • E is correct. The Date class is located in the java.util package so it needs an import, and DateFormat objects must be created using a static method such as DateFormat.getInstance() or DateFormat.getDateInstance().
  • A, B, C, and D are incorrect based on the above.

17. Which are true? (Choose all that apply.)

  1. The DateFormat.getDate() is used to convert a String to a Date instance.
  2. Both DateFormat and NumberFormat objects can be constructed to be Locale specific.
  3. Both Currency and NumberFormat objects must be constructed using static methods.
  4. If a NumberFormat instance's Locale is to be different than the current Locale, it must be specified at creation time.
  5. A single instance of NumberFormat can be used to create Number objects from Strings and to create formatted numbers from numbers.
Answer:
  • B , C, D, and E are correct.
  • A is incorrect, DateFormat.parse() is used to convert a String to a Date.

18. Which will compile and run without exception? (Choose all that apply.)

  1. System.out.format("%b", 123);
  2. System.out.format("%c", "x");
  3. System.out.printf("%d", 123);
  4. System.out.printf("%f", 123);
  5. System.out.printf("%d", 123.45);
  6. System.out.printf("%f", 123.45);
  7. System.out.format("%s", new Long("123"));
Answer:
  • A , C, F, and G are correct. The %b (boolean) conversion character returns true for any non-null or non-boolean argument.
  • B is incorrect, the %c (character) conversion character expects a character, not a String. D is incorrect, the %f (floating-point) conversion character won't automatically promote an integer type. E is incorrect, the %d (integral) conversion character won't take a floatingpoint number. (Note: The format() and printf() methods behave identically.)

19. Given:

1. import java.util.*; 
2. class Brain { 
3. public static void main(String[] args) {
4. // insert code block here 
5. } 
6. }
Which, inserted independently at line 4, compile and produce the output "123 82" ? (Choose all that apply.)
  1. Scanner sc = new Scanner("123 A 3b c,45, x5x,76 82 L"); 
    while(sc.hasNextInt()) System.out.print(sc.nextInt() + " ");
    
  2. Scanner sc = new Scanner("123 A 3b c,45, x5x,76 82 L"). useDelimiter(" "); 
    while(sc.hasNextInt()) System.out.print(sc.nextInt() + " ");
    
  3. Scanner sc = new Scanner("123 A 3b c,45, x5x,76 82 L"); 
    while(sc.hasNext()) { 
     if(sc.hasNextInt()) System.out.print(sc.nextInt() + " "); 
     else sc.next(); 
    }
    
  4. Scanner sc = new Scanner("123 A 3b c,45, x5x,76 82 L"). useDelimiter(" "); 
    while(sc.hasNext()) { 
     if(sc.hasNextInt()) System.out.print(sc.nextInt() + " "); 
     else sc.next(); 
    }
    
  5. Scanner sc = new Scanner("123 A 3b c,45, x5x,76 82 L"); 
    do {
     if(sc.hasNextInt()) System.out.print(sc.nextInt() + " "); 
    } while ( sc.hasNext() );
    
  6. Scanner sc = new Scanner("123 A 3b c,45, x5x,76 82 L"). useDelimiter(" "); 
    do { 
     if(sc.hasNextInt()) System.out.print(sc.nextInt() + " "); 
    } while ( sc.hasNext() );
    
Answer:
  • C and D are correct. Whitespace is the default delimiter, and the while loop advances through the String using nextInt() or next().
  • A and B are incorrect because the while loop won't progress past the first non-int. E and F are incorrect. The do loop will loop endlessly once the first non-int is found because hasNext() does not advance through data.
BACK