• 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

Java NIO2 - Question about directories created from symbolic link - OCP 8 Book/CH9 Selikoff/Boyarsky

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

Chapter 9 question from OCP 8 Study Guide by Selikoff/Boyarsky

Assume /kang exists as a symbolic link to the directory /mammal/kangaroo within the file system. Which of the following statements are correct about this code snippet? (Choose all that apply.)



Answer options are:
A. A new directory will always be created.
B. A new directory will be created only if /mammal/kangaroo exists.
C. If the code creates a directory, it will be reachable at /kang/joey.
D. If the code creates a directory, it will be reachable at /mammal/kangaroo/joey.
E. The code does not compile.
F. The code will compile but always throws an exception at runtime.

C and D both marked as correct answer.
Explanation says : If /mammal/kangaroo does exist, then the directory will be created at /mammal/kangaroo/joey, and because the symbolic link would be accessible as /kang/joey, C and D are both correct.

Could you please explain why (in which circumstances) would symbolic link be accessable as /kang/joey?

Thanks in advance

 
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
John,
Thanks for asking. This is actually how symbolic links work

$ pwd
/tmp
$ mkdir one
$ mkdir one/two
$ ln -s one/two link
$ ls -l
total 8
lrwxr-xr-x 1 nyjeanne wheel 7 Jun 11 16:15 link -> one/two
drwxr-xr-x 3 nyjeanne wheel 102 Jun 11 16:15 one
$ mkdir one/two/joey
$ cd link/joey
$ pwd
/tmp/one/two/joey

Notice how you can treat the symbolic link as the same as what it references. In this example cd one/two/joey and cd link/joey do the same thing.

In question #5 from the book, /kang links to /mammal/kangaroo. This means cd /kang/joey and cd /mammal/kangaroo/joey do the same thing.
 
John Longer
Greenhorn
Posts: 16
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. So it mean that created directory just would be reachable via /kang/joey, but actual created directory would be /mammal/kangaroo/joey, correct?
 
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

John Longer wrote:Thanks. So it mean that created directory just would be reachable via /kang/joey, but actual created directory would be /mammal/kangaroo/joey, correct?


You got it!
 
John Longer
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I see, thanks.
 
You've gotta fight it! Don't give in! Read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic