Question : Which of the following is a correct override for extending the ListResourceBundle class?
1. public HashMap getContents() { Map contents = new HashMap<>(); contents.add("Hadoop", "Exam"); return contents; }
2. public Object[] getContents() { return new Object[] { { "Hadoop" } , { "Exam" } }; }
3. public Object[][] getContents() { return new Object[][] { { "Hadoop", "Exam" } }; }
4. public String[] getKeysAndValues() { return new String[] { { "Hadoop" } , { "Exam" } }; }
Correct Answer : 3 Explanation: The return type of the getContents() method is Object[][]. Further, the method should return a new object of type Object [][] from the method body.
Question : You have been given below code, what is the behavior expectd?
public static void main(String[] args) { ZonedDateTime startTime = ZonedDateTime.of(2016, 1, 01, 2, 0, 0, 0, ZoneId.of("UTC-4")); ZonedDateTime endTime = ZonedDateTime.of(2016, 1, 01, 8, 0, 0, 0, ZoneId.of("UTC-1")); long hrs = ChronoUnit.HOURS.between(startTime, endTime); // line n1 System.out.println("Total time difference is " + hrs + " hours"); } }
1. Total time difference is 4 hours
2. Total time difference is 3 hours
3. Total time difference is 2 hours
4. An exception is thrown at line n1.
Correct Answer : 2 Explanation: ZonedDateTime.of(2016, 1, 01, 2, 0, 0, 0, ZoneId.of("UTC-4")); -> UTC Time = 2+4 = 6 ZonedDateTime.of(2016, 1, 01, 8, 0, 0, 0, ZoneId.of("UTC-1") -> UTC Time = 8+1 =9
9-6=3
Question : Assume that you've the following resource bundles in your classpath: ResourceBundle.properties ResourceBundle_ar.properties ResourceBundle_en.properties ResourceBundle_it.properties ResourceBundle_it_IT_Rome.properties Also assume that the default locale is English (US), where the language code is en and country code is US. Which one of these five bundles will be loaded for the call loadResourceBundle("ResourceBundle", new Locale("fr", "CA", ""));?
1. ResourceBundle.properties
2. ResourceBundle_ar.properties
3. ResourceBundle_en.properties
4. ResourceBundle_it.properties
5. ResourceBundle_it_IT_Rome.properties
Correct Answer : 3 Explanation: Java looks for candidate locales for a base bundle named ResourceBundle and locale French (Canada), and checks for the presence of the following property files: ResourceBundle_fr_CA.properties ResourceBundle_fr.properties Since both of them are not there, Java searches for candidate locales for the base bundle named ResourceBundle and a default locale (English - United States): ResourceBundle_en_US.properties ResourceBundle_en.properties Java finds that there is a matching resource bundle, ResourceBundle_en.properties. Hence it loads this resource bundle
3. It will throw error : java.nio.file.InvalidPathException: UNC path is missing sharename: 4. java.nio.file.InvalidPathException: UNC path is missing sharename: //hadoop.txt/