• 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 / OCP Java SE 8 Programmer Practice Tests: Chapter 23 Errata

 
Greenhorn
Posts: 6
6
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code for question 4 is
According to the explanation,

Since Object, unlike String, does not have a method equalsIgnoreCase(), the lambda expression does not compile.


This explanation is incorrect, since the equalsIgnoreCase is not called on the Object, but on the string literal "bob". The correct explanation would be:

Since equalsIgnoreCase() expects a String instance as an input parameter, and not an Object, the lambda expression does not compile.



---

Question 18's code, for reference:
Answer II states, that

The design protects the password by clearing it from memory after it is entered.


The explanation says, that

While the process correctly clears the password from the char array in memory, it adds the value to the JVM string pool when it is converted to a String.


Maybe I'm wrong on this account, but:

So if I create a new String through any of the constructors, it's not going to be part of the pool, unless I explicitly call the intern() method. The StringBuffer internally works with char[], and its toString() method calls
This means that the resulting String is not going to be part of the pool, and so the correct answer is E.

---

Question 19. Answers C and D are exactly the same.

---

Question 30.

Which of the following can be independently inserted into the blank so the code can run without error for at least one SQL query?



I. System.out.println(rs.getInt(1));
II. rs.next(); System.out.println(rs.getInt(1));
III. if (rs.next()) System.out.println(rs.getInt(1));


Possible answers:

A. II
B. III
C. I and III
D. II and III
E. I, II, and III
F. None of the above


The explanation says:

If the SELECT statement has a function like count(*) or sum(*) in the first column, there will always be a row in the ResultSet, so II works as well.


Now, at the same time, if the SELECT statement results in an empty ResultSet, II is going to throw an exception. The question, again,

so the code can run without error for at least one SQL query?


This makes II an incorrect answer, and therefore the correct answer here is B.

---

Question 51.

Let’s say we have a Reader instance that will produce the characters with the numeric values {1,2,3,4,5,6,7}. Which of the following are possible outcomes of executing the checkLottoNumbers() method with this Reader instance? (Choose two.)


The code:

Possible answers:

A. An IOException on line 25
B. An IOException on line 27
C. 'c'-4 is returned.
D. 'd'-3 is returned.
E. 3-4 is returned.
F. 4-3 is returned.


The explanation:

The method does not call the markSupported() prior to calling mark() and reset(). This is considered a poor practice. The input variable could be a subclass of Reader that does not support this functionality. In this situation, the method would ignore the mark() call and throw an IOException on the reset() method, making Option A incorrect and Option B correct.


This is wrong. Here is the implementation of mark() in the Reader class, together with the javadoc:

Because of this, the correct answer to this question is A, E.

---

Question 71.

What is true about the following code? (Choose two.)



Possible answers:

A. If using a JDBC 3.0 driver, this code throws an exception.
B. If using a JDBC 4.0 driver, this code throws an exception.
C. The resources are closed in the wrong order.
D. The resources are closed in the right order.
E. The Connection is created incorrectly.
F. The Statement is created incorrectly.


According to the Answers to Review Questions, the correct answers are A, C. In a bit more detail:

JDBC 3.0 drivers require a Class.forName() call. Since this is missing, Option A is correct, and Option B is incorrect.


However, this is what the OCP book says

You might know that you can skip Class.forName on a JDBC 3.0 driver that was ahead of its time in including the java.sql.Driver file in addition to the public driver class. For the exam, go with the simplified view of the world that says it is mandatory. Of course, you would probably be using a DataSource in the first place, making this a moot point.


Now let's say I never read the book, but am aware of the truthfulness of the first sentence, and have never heard about the rest. This means I know that option A is not necessarily true. I might not have experience with derby, specifically, but I could think, why could it not have had that file there already? And finally if I also know that derby had a 10.2.1.6 driver, which was still only supporting JDBC 3.0 out of the box, but already contained the java.sql.Driver file, because it did have source codes for JDBC support, then I know for sure that option A is outright wrong.

---

Question 82. Here the problematic part is with the second part of the explanation. The problem is, Chapter 21, Question 9 already stated that

Regardless, it needs to include the database name or alias.


Contrary to this, the explanation part for Chapter 23, Question 82 states, that

If all the semicolons were changed to colons, Option D would be correct. I and V would still be incorrect because they don’t begin with the JDBC protocol and magic driver name as the first two components.


Option D says there are three valid JDBC URL formats for an imaginary driver named magic and a database named box. The original answer options:

I. jdbc;box;magic
II. jdbc;magic;@127.0.0.1:1234
III. jdbc;magic;//@127.0.0.1:1234
IV. jdbc;magic;127.0.0.1:1234/box
V. magic;jdbc;127.0.0.1:1234/box


So, according to the explanation, these would be valid JDBC URLs:

II. jdbc:magic:@127.0.0.1:1234
III. jdbc:magic://@127.0.0.1:1234
IV. jdbc:magic:127.0.0.1:1234/box


Which, according to C21Q9, is wrong, because only IV contains the database name.
 
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
It would probably be better to create a seperate topic for each question errata report. In thi way each topic can have a dedicated discussion about that question and errata report, so follow-up will be much easier.

If you create seperate topics for all questions except Q4, I'll edit your first post so only Q4 remains (and update the subject accordingly).
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:It would probably be better to create a seperate topic for each question errata report. In thi way each topic can have a dedicated discussion about that question and errata report, so follow-up will be much easier.


And an easier post for me to respond to ;). That said, it is already posted this way, so let's give it a shot. If I agree with all of them, it'll be a short thread.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OCP #4 - agreed and added to the errata

OCP #18 - While the explanation might not be 100% correct, I still think the answer is. Suppose you were to take a dump of the memory in use when this program is running. The char[] is fine. However, the String will print out in plain text. So it is still a security issue and D is still correct. If you want to discuss this one further, can you create a new thread? It's a deep and interesting topic!

OCP #19 - agreed and added to the errata. It doesn't affect the answer, but makes the question easier than we intended!

OCP #30 - I don't follow. This seems right to me. The question asks which will run without exception for at last one SQL query. Option 2 is horrible practice, but does work if the query is select count(*) from table. Making II correct and Option D the answer.

OCP #51 - I never use this API so I'd rather Scott confirm before I add it to the errata. Your report certainly looks right.

OCP #71 - As you know from our OCP book, we are frustrated with the subset of JDBC Oracle choose to include on the exam. We wrote a nice rant there. Unfortunately, that's a bit much for an explanation. I wish Class.forName wasn't on the exam. But it is. We do say that you should keep your study guide handy for this book. That's our justification for not being able to re-explain everything . In other words, I agree with you that Option A isn't correct in real life. Scott and I both have way too much real life JDBC experience making the JDBC questions hard - they go against experience and best practices.

OCP #82 - Agreed and added to errata.

 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OCP #51  Reader is an abstract class, so it's certainly possible to have a concrete instance of Reader that succeeds on mark() but fails on reset().  I'm guessing that's the class I used when I was testing it.  That said, it's also possible to have it fail on both methods.  For this reason, the correct answer is actually ABE.

Either way, the key thing you should take away from this question is that unless you call the markSupported() method, you cannot be sure if the behaviors of the mark() and reset() methods.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Scott. #51 is now added to the errata as well.
 
Tamas Szekeres
Greenhorn
Posts: 6
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the batch, at this point I was quite a bit frustrated with the book, and I only got back now with the free time to do the cutting up, but it's already too late.

About question #30, I had an epiphany. So, there are two ways to interpret this question, and the more I think of it the more sense this makes. One way to think about it - which was probably the intention from the beginning - is that there must exist at least one such query for which the code must run without errors. This essentially means that every code which printed out anything in III will also run without errors with II, making both of them correct.
I, however, managed to get a different meaning of it into my head. According to that, we're looking for a replacement which must run without error for every possible, syntactically valid SQL queries for the first query. We can later add further queries as well in the try block, but those we don't care about anymore. Something felt off about this explanation, but I couldn't put my fingers on it until just now.
Maybe a slight rewording of the question would be helpful, but now I fully understand your explanation and the reason why both II and III are correct.

On #51, I went to the abstract because that's what's supposed to specify the contract that all contcrete implementations are supposed to follow. The javadoc there says that the method should throw an IOException when mark is not supported, so from that point of view any child class that doesn't support the mark operation, but does not throw this exception on calling mark(), is violating this contract. Fun fact, after having a look around there I've stumbled upon the NullReader from apache, which actually throws an UnsupportedOperationException instead of IOE.

On #71, I'm also a bit angry with this topic, but because of a different reason. The OCP book, as you mentioned, covers a very limited area on the topic. The practice test book includes questions from some areas which were not previously covered, I guess this is because the requirements of the certification shifted a bit during those two years. But with some common sense and the explanations it is easy to understand what is happening. Still, even that didn't cover every JDBC topic on the exam, and this is fresh (as in 10 hours old), first-hand experience.

From a completely different point of view, a big kudos to both of you for putting the books together, they helped me through both the OCA and OCP exams on the first try.
 
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

Jeanne Boyarsky wrote:OCP #18 - While the explanation might not be 100% correct, I still think the answer is.


I don't know the possible answers for that question, nor the complete explanation But the quoted part of the explanation of this question is incorrect. Invoking sb.toString() won't add its value to the JVM String Literal pool (as also illustrated with the excellent code snippet of the OP). So that should definitely be added as an errata, because that's a technical error. But since the password is still somewhere in memory as plain text (by converting it into a String), it is indeed still a security issue.

 
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

Tamas Szekeres wrote:Sorry for the batch, at this point I was quite a bit frustrated with the book, and I only got back now with the free time to do the cutting up, but it's already too late.


Although splitting this huge first post into smaller (one per question) topics would be better, that post is absolutely top-notch! Appropriately using code-tags to post code snippets, nice and clear errata reports, even adding own code experiments to prove your reasoning, and so on. Cows and pie are on me! Enjoy!
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tamas,
#18 - Now added to errata

#30 - Ah. Now I understand your comments. We maintain a private list of things that aren't wrong, but could be clearer. (which is useful for a Java 9 version of the book.) I'll make a note there about being more explicit.
reply
    Bookmark Topic Watch Topic
  • New Topic