• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OCA Java SE 7 Programmer I Study guide - Chapter 2 - Self Test - Question 8

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
About the question 8 of the Self test, chapter 2 say:
You need to update a value of a hash table (that is, HashMap) where the primary key must equal a specified string. Which statements would you need to use in the implementation of this algorithm?
A. Iteration statement
B. Expression statement
C. Conditional statement
D. Transfer of control statement
Answer: A, B, and C. Iteration, expression, and conditional statements would be used to implement the algorithm.
The following code segment demonstrates the use of these statements by programmatically replacing the ring on the little finger of a person’s left hand. The statements are prefaced by comments that identify their types.


In my opinion this question is a little confuse, because if I know the key I can update a HashMap without the support of Iteration statement and without the Conditional statement as below:

If I must use the Iteration statement and the Conditional statement I can use the Transfer of control statement also.

What do you think?

Thanks
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Devenay,

In my opinion you are correct! It's actually the power of a map to be able to access/change a value by its key using an expression statement. You don't need an iteration or conditional statement at all. The first example is simply bad programming, your 2nd example is how it should be done

So that should be added as an erratum to the book.

Kind regards,
Roel
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm curious, why is there HashMap in this book? They're not listed in the OCA Java 7 exam objectives.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sika Annas wrote:I'm curious, why is there HashMap in this book? They're not listed in the OCA Java 7 exam objectives.


That's true! From the Collections framework you should only know ArrayList for the OCAJP7
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the same question Devaney addresses at the beginning of this thread, I selected "A" (Iteration statement) and "B" (Expression statement) as answers. I did this because I could think of a way to use only a "while" as shown in the code below, and come up with output identical to the author's:


I had to remove any references to "null" values and define "static String s" at the beginning of the class, but again, I got identical output and didn't use a conditional.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vince Silvey wrote:I had to remove any references to "null" values and define "static String s" at the beginning of the class, but again, I got identical output and didn't use a conditional.


Your solution gives me a NullPointerException which is not identical to the output of HashMapExampleZ.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree that this question is confusing. I ended up choosing a conditional and expression statement, but you are correct that we should only need the expression statement. I sure hope they don't have confusing questions like this on the exam!
 
Ranch Hand
Posts: 49
1
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for posting this. I just ran into the same issue. The key here is that you only NEED the expression statement. Nobody would update a value in a Map this way.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic