Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!
  • 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
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

OCP question of  RSS feed

 
Greenhorn
Posts: 2
  • 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: 39128
723
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: 2
  • 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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!