• 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

Errata for OCA/OCP Java SE 7 Programmer I & II Study Guide (K&B7)

 
Ranch Hand
Posts: 241
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Table 9-10 on page 522, last row, has a space inside the {} in the glob column. There should be no space, unless you want the space to be evaluated as part of the pattern.

{cat, dog}*


should be

{cat,dog}*

 
T Vergilio
Ranch Hand
Posts: 241
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On page 427,

should be


And

should be


Similarly, the code sample on page 428 should reflect that these are languages, not countries, when printing the output.
 
T Vergilio
Ranch Hand
Posts: 241
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On page 429, the reason why the output doesn't display the currency symbol for the Locale is because the Locale represents the French language, not the country. If you change the locale to:

Locale locFR = new Locale ("fr", "FR"); //France, the country


the output should be

2,26 €



There is no Currency for the French language:

but there is one for the country:

The API for Currency says:

If no symbol can be determined, the ISO 4217 currency code is returned.


So we should expect to have the code printed if we can't print the symbol:
 
T Vergilio
Ranch Hand
Posts: 241
5
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On page 460,

ListResourceBundles and PropertyResourceBundles do not share a hierarchy.



This is not quite right. ResourceBundle will go up the hierarchy looking for either a ListResourceBundle or a PropertyResourceBundle at each level, with ListResourceBundle having priority. Every time it goes up a level, it looks for either one or the other, but never both. In the end, you could end up with a hierarchy containing a mix of ListResourceBundles and PropertyResourceBundles, as long as these are at different levels.

Here is an example from the ResourceBundle API:

Example:

The following class and property files are provided:

MyResources.class
MyResources.properties
MyResources_fr.properties
MyResources_fr_CH.class
MyResources_fr_CH.properties
MyResources_en.properties
MyResources_es_ES.class

The contents of all files are valid (that is, public non-abstract subclasses of ResourceBundle for the ".class" files, syntactically correct ".properties" files). The default locale is Locale("en", "GB").
Calling getBundle with the locale arguments below will instantiate resource bundles as follows:

Locale("fr", "CH") MyResources_fr_CH.class, parent MyResources_fr.properties, parent MyResources.class
Locale("fr", "FR") MyResources_fr.properties, parent MyResources.class
Locale("de", "DE") MyResources_en.properties, parent MyResources.class
Locale("en", "US") MyResources_en.properties, parent MyResources.class
Locale("es", "ES") MyResources_es_ES.class, parent MyResources.class
The file MyResources_fr_CH.properties is never used because it is hidden by the MyResources_fr_CH.class. Likewise, MyResources.properties is also hidden by MyResources.class.



The first four examples instantiate a mix of ListResourceBundle and PropertyResourceBundle instances for a single getBundle() call.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mock Exam OCP Objective 12.0 Localization question 6: Should rb.getObject("key") rather than rb.getString("key") be used to get values from the Flag.java and Flag_en.java resource bundles? Otherwise there will be a ClassCastException.
My understanding is to use .java for JAVA Resource bundles and .properties for key=value pairs in Property Resource Bundles. Should key=value pairs be located in the JAVA Resource Bundles (.java files)?
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On page 272 regarding the StringBuilder reverse() method, the line of code:
StringBuilder s = new StringBuilder("A man a plan a canal Panama");
should be:
StringBuilder sb = new StringBuilder("A man a plan a canal Panama");

otherwise the rest of the code doesn't compile regarding the variable sb.
 
Ranch Hand
Posts: 386
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A very minor (and rather pedantic) error (if I've remembered correctly!)

page 603:


In the OCA part of the book, we discussed several small additions/improvements to the language that were added under the name "Project Coin"



LIES! I'm pretty sure there's been no mention of project coin so far
 
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

nick woodward wrote:


In the OCA part of the book, we discussed several small additions/improvements to the language that were added under the name "Project Coin"



LIES! I'm pretty sure there's been no mention of project coin so far


It's not an errata item, even not a very minor one. It's probably about interpretation of the statement you have quoted. There is indeed no mention of "Project Coin" in the OCA part. Project Coin was the official name of the project which collected a few small changes for JDK 7. And a few of these small changes (additions/improvements) are definitely covered in the OCA part of the book: strings in switches (page 314), binary literals (page 169), and underscores in numeric literals (page 168); but they are not covered in the OCA part under the name "Project Coin".

Hope it helps!
Kind regards,
Roel
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On the interactive quiz CD, in OCP Exam 1, there is a question involving the hashcode/equals contract (sorry, couldn't find it when checking OCP Objective 4 questions directly so I don't know which number it is, and I had the exam running randomized).

The question presents a class "sortOf" with four fields - String name, int bal, String code, and short rate (the fields are all exposed and no relationships between them are enforced by the class) - and with method hashcode() returning:


It then asks which of the four "equals()" implementations shown will fulfill the equals and hashcode contracts for that class. The CD says A and B are wrong and C is correct, and I concur. But the CD also states that D is correct:



with the explanation stating that "The equals() algorithm must be at least as precise in defining what "meaningfully equivalent" means as the hashcode() method is." However, D does not add precision, it simply changes the algorithm. The following example shows that D would not fulfill the contract:

sortOf sO1 {name = "Me", bal = 6, code = "QX", rate = 2}
sortOf sO2 {name = "Ye", bal = 4, code = "WT", rate = 3}

sO1.hashcode() = 2 * 6 = 12
sO2.hashcode() = 2 * 4 = 8
sO1.equals(sO2) = [ 2 * 6 * 2 == 2 * 4 * 3 ] = [ 24 == 24 ] = true
 
Ranch Hand
Posts: 40
2
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to the answer to Question 56 of OCP exam 2, the following statement is false: "In an assert statement, the expression after the : (colon) can be any Java expression."
The explanation is that you cannot put a method invocation of a void method after the semicolon. This may be true, but is this really an expression?

I thought an expression returns a value by definition... Because you can put any value after the colon, the statement should be true. Indeed according to the official documentation on expressions https://docs.oracle.com/javase/tutorial/java/nutsandbolts/expressions.html: "An expression is a construct made up of variables, operators, and method invocations, which are constructed according to the syntax of the language, that evaluates to a single value."

Perhaps technically a void method call is an expression just like other method calls? Still, not a well-posed question I suppose.
 
Henno Vermeulen
Ranch Hand
Posts: 40
2
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OCP mock exam Objective 11 concurrency question 1. Class Account correctly uses a ReentrantLock to protect the value field, but method getValue() doesn't use the lock to read the value field.
Correct me if I'm wrong, but this can suffer from visibility issues due to a thread caching the value.
So I selected answer A which says this class is not thread safe.

The lock should als be used to read the value, or the value field should be volatile.
 
Greenhorn
Posts: 26
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where:
Chapter 15: JDBC, page 856
Paragraph starting with "First,"
Next to last line

What:
Replace "jdbc.sql.Driver" with "java.sql.Driver"
 
Mike Petrov
Greenhorn
Posts: 26
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following suggestions cover exclusively the JDBC chapter.
Most serious ones that affect supposed language behavior are colored in blue.
I encourage someone to check my conclusions for possible mistakes as it would be a source of knowledge for me too.

Where: p. 849 (table column name) and p. 872 (code snippet on top)
Should be:
NOTE: p. 872 has already been added to errata wiki with suggestion to change "UnitPrice" to "Price" in SQL query. My suggestion is the contrary:
1) revert that record in wiki
2) change rs.getFloat("Price"); to rs.getFloat("UnitPrice"); on p. 872
3) change "Read the data in the column "Price" to "Read the data in the column UnitPrice" on p. 872
4) change "Price is the third column" to "UnitPrice is the third column" on p. 872
5) change "and Price is in position 3" to "and UnitPrice is in position 3" on p. 872
6) change column name to "UnitPrice" on p. 849
The reason is that code snippets in this chapter use the data model introduced on p. 847 extensively. After passing through the chapter, I've noted that "UnitPrice" is seen far more often than "Price". Thus moving to "UnitPrice" would involve less effort.
All of the following examples feature "UnitPrice":
  • UML diagram on p. 847
  • SQL Update on top of p. 865
  • section "getFloat" on p. 873
  • SQL Update on p. 889
  • SQL Select on p. 890
  • sections "updateRow()" and "cancelRowUpdates()" on p. 891
  • list of columns on the bottom of p. 898
  • code snippet on the bottom of p. 908
  • SQL Select on p. 909

  • Where: p. 874, "getTimestamp" (4th paragraph from the top), third line
    What: "where ffffffffff"
    Should be: there are 10 f's but should be 9 since there are 9 digits in the maximum number of nanoseconds. Previously declared form "yyyy-mm-dd hh:mm:ss.fffffffff" is correct.

    Where: p. 876, 2nd paragraph, first line
    What: "ResultSetMetaData class"
    Should be: ResultSetMetaData is an interface, not a class.


    Where: p. 876, last paragraph, sentence beginning on third line
    What: "Also, note that each column must be set to a value before the row is inserted in the database or a SQLException will be thrown"
    Should be: Only NOT NULL columns should be set to a value. No one requires you to set columns that allow for null values.


    Where: p. 876, code snippet, fourth line
    What: rs.next();
    Should be: this statement should be deleted as it's not necessary to read the RS metadata.

    Where: p. 892, last paragraph
    What: "...if you deleted row 1, the cursor is still positioned at row 1. However, if the deleted row was the last row, then the cursor is positioned after the last row".
    Should be: It seems that things work vice-versa. Check code snippets below.


    Output:
    Before delete, row #1
    After delete, row #0
    Cursor is before the first row
    org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next.


    Output:
    Before delete, row #3
    After delete, row #2
    Michael

    Where: p. 895, code snippet on top, next to last line
    What: "rsinsertRow();"
    Should be: "rs.insertRow();"

    Where: p. 896, code snippet, line "rs.moveToInsertRow();"
    What: "Move the special insert row"
    Should be: "Move to the special insert row"

    Where: p. 917, last paragraph
    What: "...and inserting a row has no effect on the current RowSet data"
    Should be: my research shows that inserting a row to RowSet causes it to appear in subsequent reads. Look at the code snippet below.


    Output:
    Michael
    Jack
    should not be visible
     
    Ranch Hand
    Posts: 460
    6
    Netbeans IDE Oracle Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi guys,

    pag 213 Self test chapter 3, question 4.
    Response to the question 4 is wrong.

    I ran the code and response is runtime exception - NullPointerException.

    Thank you!!!

    Happy  programming.
     
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    OCP Page 209 getsum() returns long instead printed Int.
     
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Chapter 8 Self Test Answers (page 474 in the text)

    E is incorrect because there is no "ride" key once we delete the parent.



    should be

    E is incorrect because there is no "train" key once we delete the child.


     
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    I'm referring to Table 5.7 "Picking a resource bundle for French in France with default locale US English" on page 264 in "Oracle Certified Professional Java SE 8 Programmer II" book.
    I think it should not contain rows (steps) 5, 6, 7, 8 (4 extra rows). The lookup for the key in bundle falls through from Zoo_fr directly to Zoo (default non-localized bundle) rather than searching through bundle set as default (and its parents) before that.

    I created some test to run and the code which confirms this behavior is here:
    https://github.com/uvsmtid/incubator/blob/403df7c18a8574ee0935d66bbe3eaa1c61e4b8f5/java.works/e416.internalization/bundle-value-resolution/src/main/java/com/spectlog/App.java#L59-L68
    * It confirms the key (default_only_us) which is supposed to be available only in default locale is actually there.
    * It prints default locale (en_US).
    * It looks up for the key available in default locale only (default_only_us).
    The last step throws MissingResourceException which confirms that bundle for default profile is not in the chain.
    I went through the source code under debugger and dynamic structure (parents chain) of the ResourceBundle objects simply does not contain bundle for default locale (en_US).

    It could be a bug in my JDK (java-1.8.0-openjdk-1.8.0.111-3.b16.fc24.x86_64 on Fedora 24), but I consider it is less likely.
     
    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
    The table on page 460 is incorrect because of this.
     
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    from OCA OCP Java SE 7 Programmer I & II Study Guide (Oracle Press Practice Exam Software)
    2.PNG
    [Thumbnail for 2.PNG]
    1.PNG
    [Thumbnail for 1.PNG]
     
    Greenhorn
    Posts: 22
    Spring AngularJS Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    In page no.804, LinkedTransferQueue is unbounded queue, so add,put and offer will not be blocked . In the example code ,its specified that it will get blocked
     
    Ranch Hand
    Posts: 91
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Greetings CodeRanchers - first time poster, so I may not be doing things properly    

    Chapter 3, page 203, second paragraph (centre of page, below code snippet):

    Since the method returns a reference to the Date object and this reference is assigned to a local variable, it will not be eligible for collection even after the getDate() method has completed.


    But as is it is not assigned to a variable in the calling method, just the getDate() method, I would have thought it is eligible. I.e. I would have expected to see
    d = doComplicatedStuff();
    or
    Date d2 = doComplicatedStuff();
    rather than just
    doComplicatedStuff();
    in the calling method.
    Or maybe I misunderstand the garbage collection rules?
     
    Elaine Byrne
    Ranch Hand
    Posts: 91
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    E Byrne wrote:Greetings CodeRanchers - first time poster, so I may not be doing things properly    
    mad wrong stuff


    Oops – re my above post: I completely misread the code and there is no issue!

    Could a moderator remove my post, if possible, please? (Looking to see if users can edit posts themselves, it seems that maybe this is no longer allowed?)

    Sorry for the inconvenience.

    Yours in embarrassment at the horror of my first post CodeRanch post being composed entirely of stupidity  

    E Byrne
     
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Roger Jenkins wrote:On page 272 regarding the StringBuilder reverse() method, the line of code:
    StringBuilder s = new StringBuilder("A man a plan a canal Panama");
    should be:
    StringBuilder sb = new StringBuilder("A man a plan a canal Panama");

    otherwise the rest of the code doesn't compile regarding the variable sb.



    Has this been reviewed for addition to the errata page? The publisher has received a second report of the issue.

    Lisa
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic