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)
Exception in thread "main" java.nio.file.NoSuchFileException: C:\data\file22.txt
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)
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.
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.
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.
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.
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.
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.
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?