• 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

Wrong answer: OCP Oracle Certified Professional Java SE 8 Programmer II - Chapter 9 page 499 Q.7

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer from the Review questions in OCP Oracle Certified Professional Java SE 8 Programmer II - Chapter 9( page 499) Question.7 is wrong:
In general both x1 and x2 lines are not compiling as there is checked IOException which should be caught or declared - which means that both D and E should be correct answers.
they say that the correct one is F....

7. If the current working directory is /zoo, and the path /zoo/turkey does not exist, then
what is the result of executing the following code? (Choose all that apply.)

Path path = Paths.get("turkey");
if(Files.isSameFile(path,Paths.get("/zoo/turkey"))) // x1
Files.createDirectory(path.resolve("info")); // x2

A. The code compiles and runs without issue, but it does not create any directories.
B. The directory /zoo/turkey is created.
C. The directory /zoo/turkey/info is created.
D. The code will not compile because of line x1.
E. The code will not compile because of line x2.
F. It compiles but throws an exception at runtime.

This should be corrected as either the exception is caught/declare or change the answers to  D and E.
 
Mariya Beleva
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually the same issue with Q.11 on page 500,same topic:
again both copy() and isSameFile() methods throws checked exception so it should be caught or declared...
The answer should be D and E, they say it is A.

11. For the copy() method shown here, assume that the source exists as regular file and that
the target does not. What is the result of the following code?
Path path1 = Paths.get("./goat.txt").normalize(); // k1
Path path2 = Paths.get("mule.png");
Files.copy(path1,path2,StandardCopyOption.COPY_ATTRIBUTES); //k2
System.out.println(Files.isSameFile(path1, path2)); //k3

A. It will output false.
B. It will output true.
C. It does not compile because of line k1.
D. It does not compile because of line k2.
E. It does not compile because of line k3.
F. It compiles but throws an exception at runtime.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The pieces of code that are provided are missing context. Yes, these methods throw an exception, but the context doesn't make it clear whether or not these are caught / declared to be thrown.

I think that in these examples, the code only does not compile because of checked exceptions if you see the code in its context. If you're missing context, you can probably assume that the enclosing code either catches the exceptions, or declares to throw them.
 
Mariya Beleva
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It was good to know that before the exam.
Thank you for the clarification.
 
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
Rob is correct. This is actually listed in the exam assumptions - if code is not a method, you have to assume the surrounding method is provided correctly.
 
reply
    Bookmark Topic Watch Topic
  • New Topic