OCP Question 31, Explanation

Given the content of /res/GoVPN.properties:


and given the code fragment:

Properties prop = new Properties();
FileInputStream fis = new FileInputStream("/res/GoVPN.properties");
System.out.println(prop.getProperty("option2", "Opera ver.46.0"));   //line n1

What is the result?

A. SoftEther
Opera ver.46.0
followed by an Exception stack trace
B. SoftEther
followed by an Exception stack trace
C. SoftEther
Opera ver.46.0

D. A compilation error occurs at line n1


The correct answer is C.


The getProperty(String key, String defaultValue) method on line n1 searches for the property against the specified key. If key is not found, the method returns the defaultValue argument. This eliminates options B and D because all LOCs are clean.

Meanwhile, the javadoc for the overloaded getProperty(String key) method says that “The method returns null if the property is not found”.

Also please note that this problem is formulated incorrectly: the option1 key gets mapped to whatever sits after the separator (minus the prepended optional space(s), which are absent in our case), which means that double quotes will be printed, too. After the exam I sent a letter to Oracle telling them about this – and about two more cases (on the ATOMIC_MOVE option in Files.move() and a Map created by collect() with Collectors.groupingBy() and Collectors.mapping() args). Chances are by the time you read this, the Oracle cert team will have already taken care of those typos and ambiguities. Quite unlikely, though.

Prep notes on Localization are here.

Leave Comment

Your email address will not be published.