-
Notifications
You must be signed in to change notification settings - Fork 1
/
OCJPJ7-Objective5.questions
287 lines (259 loc) · 9.95 KB
/
OCJPJ7-Objective5.questions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QuestionSet SYSTEM "inquisitionQuestions.dtd">
<QuestionSet version="4">
<Name>Localization</Name>
<Description><![CDATA[Questions on Java SE 7 (Objecive 5: Localization)
<hr>
<b>Info:</b><br>
<ul>
<li>Maintainer: Jonas <a href="mailto:jonas.fiala@gmail.com">jonas.fiala@gmail.com</a>
<li>Home page: <a href="https://github.com/georgy/OCPJP">github</a>
<li>Version: 0.1
<li>Date published: 2012-12-12
<li>Licence: (Public domain, Creative Commons etc)</li>
</ul>
<ul>
<li>Objective 5.1 Describe the advantages of localizing an application </li>
<li>Objective 5.2 Define what a locale represents </li>
<li>Objective 5.3 Read and set the locale by using the Locale object </li>
<li>Objective 5.4 Build a resource bundle for each locale </li>
<li>Objective 5.5 Call a resource bundle from an application </li>
<li>Objective 5.6 Select a resource bundle based on locale </li>
<li>Objective 5.7 Format text for localization by using NumberFormat and DateFormat </li>
</ul>]]></Description>
<RecommendedTimePerQuestion>120</RecommendedTimePerQuestion>
<Category>OCPJP 7: Format text for localization by using NumberFormat and DateFormat</Category>
<Questions>
<!-- Q1 -->
<MultipleChoiceQuestion shufflable="true" singleOptionMode="true">
<QuestionText><![CDATA[Given the proper import statements and code
<java>
public class Ex1 {
public static void main(String[] args) {
// Insert code here
Date d = new Date();
System.out.println(f.format(d));
}
}
</java>
What line(s) of code inserted independently will allow the class to compile, run and output one line of text? (Choose all that apply)
]]></QuestionText>
<Options>
<Option correct="true">DateFormat f = DateFormat.getInstance();</Option>
<Option correct="true">DateFormat f = DateFormat.getDateInstance();</Option>
<Option correct="false">DateFormat f = DateFormat.getDateInstance(Locale.GERMAN);</Option>
<Option correct="false">DateFormat f = DateFormat.getDateInstance(Locale.GERMANY);</Option>
<Option correct="true">DateFormat f = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN);</Option>
<Option correct="true">DateFormat f = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMANY);</Option>
</Options>
<ExplanationText>
In terms of getDateInstance only the following method declarations are correct:
getDateInstance()
getDateInstance(int style)
getDateInstance(int style, Locale aLocale).
</ExplanationText>
</MultipleChoiceQuestion>
<!-- Q2 -->
<MultipleChoiceQuestion shufflable="true" singleOptionMode="true">
<QuestionText><![CDATA[Given the proper import statements and code
<java>
public class Ex2 {
public static void main(String[] args) {
DateFormat f = DateFormat.getInstance();
Date d = new Date();
System.out.println(f.format(d));
// Insert code here
}
}
</java>
Assume compilation works out. What would produce the equivalent output? (Choose all that apply)
<java>
1: DateFormat tf = DateFormat.getDateInstance(DateFormat.SHORT);
DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT);
System.out.println(tf.format(d) + " " + df.format(d));
2: DateFormat tf = DateFormat.getDateInstance(DateFormat.DEFAULT);
DateFormat df = DateFormat.getTimeInstance(DateFormat.DEFAULT);
System.out.println(tf.format(d) + " " + df.format(d));
3: DateFormat tf = DateFormat.getDateInstance();
DateFormat df = DateFormat.getTimeInstance();
System.out.println(tf.format(d) + " " + df.format(d));
4: DateFormat tf = DateFormat.getDateInstance(0);
DateFormat df = DateFormat.getTimeInstance(-1);
System.out.println(tf.format(d) + " " + df.format(d));
5: DateFormat tf = DateFormat.getDateInstance();
DateFormat df = TimeFormat.getTimeInstance();
System.out.println(tf.format(d) + " " + df.format(d));
</java>
]]></QuestionText>
<Options>
<Option correct="true">1st</Option>
<Option correct="false">2nd</Option>
<Option correct="false">3rd</Option>
<Option correct="false">4th</Option>
<Option correct="false">5th</Option>
</Options>
<ExplanationText>
getInstance(): Get a default date/time formatter that uses the SHORT style for both the date and the time.
</ExplanationText>
</MultipleChoiceQuestion>
<!-- Q3 -->
<MultipleChoiceQuestion shufflable="true" singleOptionMode="true">
<QuestionText><![CDATA[Given the proper import statements and code
<java>
public class Ex3 {
public static void main(String[] args) {
DateFormat f = DateFormat.getDateInstance(DateFormat.FULL, Locale.UK);
NumberFormat nf = f.getNumberFormat();
System.out.println(nf.getCurrency().getCurrencyCode() + " "+ nf.format(15000000L));
}
}
</java>
If you try to compile and run this progam, what would be the result?
]]></QuestionText>
<Options>
<Option correct="false">Compile time error.</Option>
<Option correct="false">Exception thrown at runtime.</Option>
<Option correct="false">Program compiles and runs with exit code 0, printing: "£ 15000000L"</Option>
<Option correct="false">Program compiles and runs with exit code 0, printing: "£ 15000000"</Option>
<Option correct="false">Program compiles and runs with exit code 0, printing: "GBP 15000000L"</Option>
<Option correct="true">Program compiles and runs with exit code 0, printing: "GBP 15000000"</Option>
</Options>
<ExplanationText>
</ExplanationText>
</MultipleChoiceQuestion>
<!-- Q4 -->
<MultipleChoiceQuestion shufflable="true" singleOptionMode="true">
<QuestionText><![CDATA[Given the proper import statements and code
<java>
public class Ex4 {
public static void main(String[] args) {
NumberFormat f = NumberFormat.getInstance();
f.setMaximumFractionDigits(0);
try {
System.out.println( f.parse("3.14") );
} catch (ParseException e) {
System.out.println("HUHU");
}
}
}
</java>
If you try to compile and run this progam, what would be the result? (Assume UK locale)
]]></QuestionText>
<Options>
<Option correct="true">3.14</Option>
<Option correct="false">3,14</Option>
<Option correct="false">HUHU</Option>
<Option correct="false">Exception thrown at runtime</Option>
</Options>
<ExplanationText>
3.14 -- setMaximumFractionDigits() setting doesn't affect NumberFormat.parse() .
</ExplanationText>
</MultipleChoiceQuestion>
<!-- Q5 -->
<MultipleChoiceQuestion shufflable="true" singleOptionMode="true">
<QuestionText><![CDATA[Given the proper import statements and code
<java>
public class Ex5 {
public static void main(String[] args) {
NumberFormat f = NumberFormat.getInstance();
f.setMaximumFractionDigits(0);
try {
System.out.println( f.format( f.parse("3.14") ) );
} catch (ParseException e) {
System.out.println("HUHU");
}
}
}
</java>
If you try to compile and run this program, what would be the result? (Assume UK locale)
]]></QuestionText>
<Options>
<Option correct="false">3.14</Option>
<Option correct="true">3</Option>
<Option correct="false">HUHU</Option>
<Option correct="false">Exception thrown at runtime</Option>
</Options>
<ExplanationText>
3 is correct since setMaximumFractionsDigits() affects NumberFormat.format()
</ExplanationText>
</MultipleChoiceQuestion>
<!-- Q6 -->
<MultipleChoiceQuestion shufflable="true" singleOptionMode="true">
<QuestionText><![CDATA[Given the proper import statements and code
<java>
public class Ex6 {
public static void main(String[] args) {
Locale loc = Locale.getDefault();
ResourceBundle rb = ResourceBundle.getBundle("Ex6", loc);
System.out.println( rb.getString("some") );
}
}
</java>
Which filenames must be present on the classpath to make program run correctly (i.e. exit with code 0)? (Assume Windows OS, US locale)
]]></QuestionText>
<Options>
<Option correct="true">ex6.properties</Option>
<Option correct="true">Ex6.properties</Option>
<Option correct="false">Ex6_default.properties</Option>
<Option correct="false">Ex6_en_GB.properties</Option>
<Option correct="false">Ex6_GB_en.properties</Option>
</Options>
<ExplanationText>
</ExplanationText>
</MultipleChoiceQuestion>
<!-- Q7 -->
<MultipleChoiceQuestion shufflable="true" singleOptionMode="true">
<QuestionText><![CDATA[Given the proper import statements and code
<java>
public class Ex6 {
public static void main(String[] args) {
Locale loc = Locale.getDefault();
ResourceBundle rb = ResourceBundle.getBundle("Ex6", loc);
System.out.println( rb.getString("another") );
}
}
</java>
Ex6.properties:
some = value
#EOF
If you try to compile and run this program, what would be the program output? (Assume UK locale, choose all that apply)
]]></QuestionText>
<Options>
<Option correct="false">Compile time exception</Option>
<Option correct="true">Exception thrown at runtime</Option>
<Option correct="true">MissingResourceException</Option>
<Option correct="false">NullPointerException</Option>
<Option correct="false">AttributeException</Option>
</Options>
<ExplanationText>
</ExplanationText>
</MultipleChoiceQuestion>
<!-- Q8 -->
<MultipleChoiceQuestion shufflable="true" singleOptionMode="true">
<QuestionText><![CDATA[Given the proper import statements and code
<java>
public class Ex6 {
public static void main(String[] args) {
Locale loc = Locale.CANADA_FRENCH;
ResourceBundle rb = ResourceBundle.getBundle("Ex6", loc);
System.out.println( rb.getString("another") );
}
}
</java>
Ex6_fr_CA.properties:
some = value
#EOF
If you try to compile and run this program, what would be the program output? (Assume Canada(Fr) locale, choose all that apply)
]]></QuestionText>
<Options>
<Option correct="false">Compile time exception</Option>
<Option correct="true">Exception thrown at runtime</Option>
<Option correct="true">MissingResourceException</Option>
<Option correct="false">NullPointerException</Option>
<Option correct="false">AttributeException</Option>
</Options>
<ExplanationText>
</ExplanationText>
</MultipleChoiceQuestion>
</Questions>
</QuestionSet>