THE OCP EXAM TOPICS COVERED IN THIS PRACTICE TEST INCLUDE THE FOLLOWING:
Which is not a locale?
When localizing an application, which type of data varies in presentation depending on locale?
How do you find out the locale of the running program?
If your application has all town names in a single file named strings.properties, what is the most specific process that has been implemented?
Which interfaces does Properties implement?
Which filename extension can hold a String property value in a resource bundle?
How long will the effects of calling Locale.setDefault() be active assuming no other calls to that method are made?
Given this properties file used to load the Properties object props and this code snippet, what is the output?
mystery=bag
type=paper
18: System.out.print(props.getProperty("mystery"));
19: System.out.print(" ");
20: System.out.print(props.getProperty("more"));
Fill in the blanks to complete the following code for a Java resource bundle.
public class Flights_en extends __________ {
protected Object[][] __________() {
return new Object[0][0];
}
}
Which of the following shows a valid Locale format for the language Hindi and the country India?
If the key purple is in all four of these files, which file will the following code use for the resource bundle?
Locale.setDefault(new Locale("en", "US"));
ResourceBundle rb = ResourceBundle.getBundle("Colors");
rb.getString("purple");
What is the output of the following?
package counter;
import java.util.*;
public class CountResource extends ListResourceBundle {
private int count = 0;
@Override
protected Object[][] getContents() {
return new Object[][] { { "count", count++ } };
}
public static void main(String[] args) {
ResourceBundle rb = ResourceBundle.getBundle("counter.CountResource");
System.out.println(rb.getObject("count") + " " + rb.getObject("count"));
}
}
Which of the following shows a valid Locale format?
Which filename extension can define a LocalDateTime property value in a resource bundle?
What happens if you run this code with no resource bundles available?
ResourceBundle rb = ResourceBundle.getBundle("ghost.None");
What is the result of the following?
Map<String, String> map = new TreeMap<>();
map.put("tool", "hammer");
map.put("problem", "nail");
Properties props = new Properties(); // p1
map.forEach((k,v) -> props.put(k, v)); // p2
String t = props.get("tool"); // p3
String n = props.get("nail");
System.out.println(t + " " + n);
Which filename extension can hold a LocalDateTime property key in a resource bundle?
If the key purple is in all four of these files, which file will the following code use for the resource bundle?
Locale.setDefault(new Locale("en", "US"));
ResourceBundle rb = ResourceBundle.getBundle("Colors");
rb.getString("purple");
Fill in the blank so the code correctly compiles and creates a Locale.
Locale loc = Locale.____________________;
What is the result of the following?
Map<Object, Object> map = new TreeMap<>();
map.put("tool", "hammer");
map.put("problem", "nail");
Properties props = new Properties(); // p1
map.forEach((k,v) -> props.put(k, v)); // p2
String t = props.getProperty("tool"); // p3
String n = props.getProperty("problem");
System.out.println(t + " " + n);
What is the output of the following?
1: package keyboard;
2: import java.util.*;
3:
4: public class Type {
5: protected Object[][] getContents() {
6: return new Object[][] { { "keys", new ArrayList<String>() }};
7: }
8: public static void main(String[] args) {
9: ResourceBundle rb = ResourceBundle.getBundle("keyboard.Type");
10: List<String> keys = (List) rb.getObject("keys");
11: keys.add("q");
12: keys.add("w");
13: keys.add("e");
14: keys.add("r");
15: keys.add("t");
16: keys.add("y");
17: System.out.println(((List) rb.getObject("keys")).size());
18: }
19: }
How many lines does the following print out?
3: Locale.setDefault(Locale.KOREAN);
4: System.out.println(Locale.getDefault());
5: Locale.setDefault(new Locale("en", "AU"));
6: System.out.println(Locale.getDefault());
7: Locale.setDefault(new Locale("EN"));
8: System.out.println(Locale.getDefault());
Given this properties file used to load the Properties object props and this code snippet, what is the output?
mystery=bag
type=paper
18: System.out.print(props.getProperty("mystery", "?"));
19: System.out.print(" ");
20: System.out.print(props.getProperty("more", "?"));
Given the following four properties files, what does this code print?
Locale.setDefault(new Locale("en", "US"));
ResourceBundle rb = ResourceBundle.getBundle(
"Cars", new Locale("fr", "FR"));
System.out.println(rb.getString("country") + " "
+ rb.getString("engine"));
Given the four properties files in question 24, what does this code print?
Locale.setDefault(new Locale("en", "US"));
ResourceBundle rb = ResourceBundle.getBundle(
"Cars", new Locale("fr", "CA"));
System.out.println(rb.getString("engine") + " "
+ rb.getString("horses"));
Given the four properties files in question 24, what does this code print?
Locale.setDefault(new Locale("fr", "CA"));
ResourceBundle rb = ResourceBundle.getBundle(
"Cars", new Locale("en", "CA"));
System.out.println(rb.getString("engine") + " "
+ rb.getString("horses"));
Which statement about ListResourceBundle is true?
If the key red is in all four of these files, which file will the following code use for the resource bundle?
Locale loc = new Locale("zh", "CN");
Locale.setDefault(new Locale("en", "US"));
ResourceBundle rb = ResourceBundle.getBundle("Colors", loc);
rb.getString("red");
What is the output of the following?
package counter;
import java.util.*;
public class PropertyCounter extends ListResourceBundle {
private int count = 0;
@Override
protected Object[][] getContents() {
return new Object[][] {{ "count", new PropertyCounter() }};
}
public int getCount() {
return count++;
}
public static void main(String[] args) {
ResourceBundle rb = ResourceBundle.getBundle("counter.PropertyCounter");
PropertyCounter obj = (PropertyCounter) rb.getObject("count");
System.out.println(obj.getCount() + " " + obj.getCount());
}
}
What is the output of the following?
1: package keyboard;
2: import java.util.*;
3:
4: public class Type extends ListResourceBundle {
5: protected Object[][] getContents() {
6: return new Object[][] { { "keys", new ArrayList<String>() }};
7: }
8: public static void main(String[] args) {
9: ResourceBundle rb = ResourceBundle.getBundle("Type");
10: List<String> keys = (List) rb.getObject("keys");
11: keys.add("q");
12: keys.add("w");
13: keys.add("e");
14: keys.add("r");
15: keys.add("t");
16: keys.add("y");
17: System.out.println(((List) rb.getObject("keys")).size());
18: }
19: }
Given the following snippets of resource bundles from when we compiled the application, what is the result of the following?
Locale.setDefault(new Locale("en", "US"));
ResourceBundle rb = ResourceBundle.getBundle("Buggy");
System.out.println(rb.getString("wheels"));
Given the snippets of resource bundles in question 31 from when we compiled the application, what is the result of the following?
Locale.setDefault(new Locale("en"));
ResourceBundle rb = ResourceBundle.getBundle("Buggy");
System.out.println(rb.getString("color"));
Given the snippets of resource bundles in question 31 from when we compiled the application, what is the result of the following?
Locale.setDefault(new Locale("zh"));
ResourceBundle rb = ResourceBundle.getBundle("Buggy");
System.out.println(rb.getString("wheels"));
If the key red is in all three of these files, which file will the following code use for the resource bundle?
Locale loc = new Locale("zh", "CN");
Locale.setDefault(new Locale("en", "US"));
ResourceBundle rb = ResourceBundle.getBundle("Colors", loc);
rb.getString("red");
Which can fill in the blank in this code?
Properties props = new Properties();
props.__________("x");
What is the output of the following?
1: package keyboard;
2: import java.util.*;
3:
4: public class Type extends ListResourceBundle {
5: protected Object[][] getContents() {
6: return new Object[][] { { "keys", new ArrayList<String>() }};
7: }
8: public static void main(String[] args) {
9: ResourceBundle rb = ResourceBundle.getBundle("keyboard.Type");
10: List<String> keys = (List) rb.getObject("keys");
11: keys.add("q");
12: keys.add("w");
13: keys.add("e");
14: keys.add("r");
15: keys.add("t");
16: keys.add("y");
17: System.out.println(((List) rb.getObject("keys")).size());
18: }
19: }
What is the result of the following?
Map<String, String> map = new TreeMap<>();
map.put("tool", "hammer");
map.put("problem", "nail");
Property props = new Property(); // p1
map.forEach((k,v) -> props.put(k, v)); // p2
String t = props.getProperty("tool"); // p3
String n = props.getProperty("nail");
System.out.println(t + " " + n);
What is the output of the following?
package counter;
import java.util.*;
public class CountResource extends ListResourceBundle {
private int count = 0;
@Override
protected Object[][] getContents() {
return new Object[][] { { "count", count++ } };
}
public static void main(String[] args) {
ResourceBundle rb = new ResourceBundle("counter.CountResource");
System.out.println(rb.getObject("count") + " " + rb.getObject("count"));
}
}
Given the following two properties files in the pod package, what does the following class output?
pod.container.properties
name=generic
number=2
pod.container_en.properties
name=Docker
type=container
package pod;
import java.util.*;
public class WhatKind {
public static void main(String[] args) {
Locale.setDefault(new Locale("en"));
ResourceBundle rb = ResourceBundle.getBundle("pod.container");
String name = rb.getString("name");
String type = rb.getString("type");
System.out.println(name + " " + type); }
}
If the key red is in all three of these files, which file will the following code use for the resource bundle?
Locale loc = new Locale("zh", "CN");
Locale.setDefault(new Locale("en", "US"));
ResourceBundle rb = ResourceBundle.getBundle("Colors", loc);
rb.getString("red");