• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

OCP question of  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you help me on question of OCA / OCP Java SE 8 Programmer Practice Tests by Scott Selikoff and Jeanne Boyarsky.

Chapter 22 question no 8
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"));

now to options:
A. bag
B. bag null
C. bag ?
D. This code throws a runtime exception on line 20.


here answer b from the book  but it should be d as it can not find the correct key .So please give your review ?
 
author & internet detective
Posts: 39206
726
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch and thank you for asking!

The book is correct.You can even try it without the bother of creating a file:


Also the JavaDoc for getProperty() includes

Searches for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns null if the property is not found.

 
Dhananjaykumar Kushwaha
Greenhorn
Posts: 7
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for solving and clear my doubts. Generally, I was confused between properties getProperty() and Resourcebundle getString() method. As one throw exception when not found a proper key while another print null.Thanks for it.
 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!