• 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

Online mock exams, batch 3, Path question. Wrong answer letter (must be C & E)

 
Greenhorn
Posts: 9
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question:
Assuming the current directory is /home and the directories and files referenced by the program exist, what is true about the following code snippet? (Choose all that apply.)

Path path1 = Paths.get("/lemur/habitat/./party.txt");
Path path2 = path1.subpath(1,4).toAbsolutePath();
System.out.println(Files.lines(path2)
 .flatMap(p -> Stream.of(p.split(",")))
 .filter(s -> s.trim().length()>0)
 .allMatch(s -> s.length()>3));

A. It will access the file /lemur/habitat/party.txt.
B. It will access the file /habitat/party.txt.
C. It will access the file /home/habitat/party.txt.
D. If the String value ,,, is contained within the file, it will definitely print false.
E. If the String value ,hat, is contained within the file, it will definitely print false.
F. It will always print false.
G. The code does not compile

Answer: B, E
-----------
The problem is answer should be C, E. Even description inside answer matches C option. The description says:
"The value path1.subpath(1,4) returns habitat/./party.txt, which we join to the current directory /home with the toAbsolutePath() method in order to see that we are accessing the file /home/habitat/party.txt"

 
author & internet detective
Posts: 41860
908
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
Agreed. This is already in the errata (search for Lemur) and was originally reported  here
 
Tahir Abdullayev
Greenhorn
Posts: 9
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My bad. I didn't checked errata for Mock exams. I thought it's only for the book.
 
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

Tahir Abdullayev wrote:My bad. I didn't checked errata for Mock exams. I thought it's only for the book.


No worries. It's not that easy to parse the errata for the mock exams because there's no question numbers to reference. (The questions are presented in a different order each time.)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic