• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

OCP Java SE 11 Programmer II Study Guide (Sybex 816) Possible Errata Chapter 9 (NIO.2)

 
Greenhorn
Posts: 17
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Chapter 9 (NIO.2) review question 22. According to the book is with correct answers B and E.

Decided to test the method provided with the following code:



Manually created the file C:\data\file19.txt with the following content:

"File 12344
rrrr
ssss"

The file: C:\data\file22.txt does not exists.

Executed the sequence of commands:

C:\Users\borko\IdeaProjects\2Chapter9\src\test\q22>set JAVA_HOME=C:\Program Files\Java\jdk-11.0.11

C:\Users\borko\IdeaProjects\2Chapter9\src\test\q22>set Path=%JAVA_HOME%\bin;%Path%

C:\Users\borko\IdeaProjects\2Chapter9\src\test\q22>java --version
java 11.0.11 2021-04-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.11+9-LTS-194)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.11+9-LTS-194, mixed mode)

C:\Users\borko\IdeaProjects\2Chapter9\src\test\q22>java Q22.java
Exception in thread "main" java.nio.file.NoSuchFileException: C:\data\file22.txt
       at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:85)
       at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
       at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
       at java.base/sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:235)
       at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:478)
       at java.base/java.nio.file.Files.newOutputStream(Files.java:220)
       at java.base/java.nio.file.Files.newBufferedWriter(Files.java:2920)
       at java.base/java.nio.file.Files.newBufferedWriter(Files.java:2963)
       at test.q22.Q22.duplicateFile(Q22.java:10)
       at test.q22.Q22.main(Q22.java:20)

Based of this answer C is correct instead of answer B => the correct answers are C and E.

My English is poor. I have a question. Is "by" optional in the statements like "referenced by x"?
In the list of possible answers "by" is written in A and B, but is missing in C and D.

The paths in some of the questions are system dependent. If a reader uses Windows OS some of the explanations are affected.
For example when explaining the answer of  review question 1 we see: "Finally, if the
value on line 5 was assigned to path and printed on line 6, then option A would be correct."
In fact if we use Windows the output is possible to be: ..\..\ lion instead of ../../lion making option D would be correct instead of A. (because of the separators)



 
Ranch Foreman
Posts: 627
13
Eclipse IDE Postgres Database C++ Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Borislav:

Please post the entirety of the question and the answer choices here so that people who don't have the study guide can help answer the questions.

In general, it is not cool to post any copyrighted materials, but the Authors of the Sybex books use this as the place to provide support both by themselves and with the aid of volunteers here, so go right ahead.

I am interested in particular, because while I absolutely love this book series, I felt that the coverage of the various values for StandardOpenOption, including StandardOpenOption.APPEND was confusing or misleading.  I have a thread going already with my confusion/complaints about that.
 
Jesse Silverman
Ranch Foreman
Posts: 627
13
Eclipse IDE Postgres Database C++ Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In particular, do you still have a confusion or a suggested errata after reading how APPEND actually works in my other thread?
https://coderanch.com/t/743960/java/StandardOpenOption
 
Borislav Mirchev
Greenhorn
Posts: 17
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jesse:

Thank you for the attention!

Q22 is like the following:

Assuming the path referenced by m exists as a file, which statements about the following method are
correct? (Choose all that apply.)

A. If the path referenced by x does not exist, then it correctly copies the file.
B. If the path referenced by x does not exist, then a new file will be created.
C. If the path referenced x does not exist, then an exception will be thrown at runtime.
D. If the path referenced x exists, then an exception will be thrown at runtime.
E. The method contains a resource leak.
F. The method does not compile.

It is amazing how much time and efforts you put on exploring this subject.

I spent some time on reading the suggested thread.

On my opinion what best explains the APPEND's behaviour is:
// append to an existing file, fail if the file does not exist
   out = Files.newOutputStream(path, APPEND);

This is a possible reason to have C, E correct but not B, E as is written in the book.
 
Jesse Silverman
Ranch Foreman
Posts: 627
13
Eclipse IDE Postgres Database C++ Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with you on the answers.

I have spent more time on some things that were less important!

I've been opening files for WRITE/APPEND since I was a kid, for decades now, and the description looked wrong to me as soon as I read it.
However, I have never used NIO.2 before late last week, so I went on a search and wrote some code as you did to check.

I would submit that opening a file for APPEND, but expecting to create it if it doesn't exist already, is far from some crazy corner case, I probably have done it 500 different times in my life in 6 to 10 different languages.

I think we have access to correct descriptions of the behavior, including the one you quoted, but the fact that the suggested answers are wrong does, I believe, verify that the Javadocs brief descriptions and those written in these (otherwise quite excellent) books are confusing or misleading.

A lawyer might be able to defend them as correct, but I believe both of us (and perhaps the authors) all got confused here.

Thanks for supplying the info, I actually have the book and am working towards those questions right now, but others here do not.
 
Borislav Mirchev
Greenhorn
Posts: 17
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For me from a practical perspective it is important to know there are such options available. After some experiments, online searching and testing the right combination of options will be found.

In general I like programming. But when it is done for business under pressure, limitations and not good interaction with people the situation is possible to be changed.

The software industry is rapidly changing and writing/reading adequate books following its steps I suspect is not an easy task. Furthermore - it is human to err. I hope thinking on the details makes us better developers.
 
Jesse Silverman
Ranch Foreman
Posts: 627
13
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agreed on all points.
I believe the authors of the book in question know that I am (mostly) so annoying about possible errors because I consider the book(s) to be so important a source for so many people.
Also, I do admit to being super-defensive when I score less than 85% on a chapter test and any of the answers seem questionable.
Compared to the history of Java Certifications, the 819 is quite hard, you have to know stuff very well and recall it all very quickly.  Preparation is challenging.
 
Borislav Mirchev
Greenhorn
Posts: 17
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think another source of difficulty is Java became "too big". It is 25+ years old. I suppose it is hard to be covered by a book with reasonable number of pages.  The situation is very interesting for the newcomers to the language. I think it is possible to be a reason some companies to switch to languages like Kotlin. After some period writing to such a language it becomes a challenge to return back to Java even having a good experience with it. I think our discussion is interesting, but went too far from the initial subject.
 
author & internet detective
Posts: 40677
827
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
You are correct. This is in the errata and was initially reported here
 
Borislav Mirchev
Greenhorn
Posts: 17
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeanne,
Excuse me for the verbose initial post and missing the appearance of "C instead of B" in the errata list and the topic dedicated to it!
I also mentioned two more things - "by usage" and "system dependent paths". (The last two paragraphs of the initial post.) What about them?



 
Jeanne Boyarsky
author & internet detective
Posts: 40677
827
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh sorry. I didn't read the whole post. I stopped reading when I saw it was a duplicate .

That's a good point. We should get rid of "None of the above" from question 1 so it is obvious that we aren't looking at windows here.
reply
    Bookmark Topic Watch Topic
  • New Topic