About Question enthuware.ocpjp.v8.2.1601 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
eddie3
Posts: 14
Joined: Sat Dec 17, 2016 10:17 pm
Contact:

About Question enthuware.ocpjp.v8.2.1601 :

Post by eddie3 »

Shouldn't the answer of this question be ..\z?
Because Paths.get("x\\y"); denotes to a relative path, not an absolute one, since there is no drive name in the path. Paths.get("z"); is also a relative path. Therefore, Java will treat as if they are in the same parent directory when called relativize( ) and output "../z".

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1601 :

Post by admin »

Yes, you may assume that x and z's parent dir is same. But you are relativizing x\\y with respect to z. So to go from y to z, you will need to do ..\..\z.
First dot dot will take you from y to x, second .. will take you from x to the common parent dir, and then z will take you to z.
If you like our products and services, please help us by posting your review here.

jankur
Posts: 11
Joined: Wed Dec 07, 2016 3:21 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1601 :

Post by jankur »

Hi, on Windows 10 + Oracle Java 1.8.0_152 the output is indeed: "..\..\z", but on Xubuntu 17.10 + Oracle Java 1.8.0_121 the output is: "../z", so I think this question and the individual explanations for options are platform-dependent. Of course we can infer that the correct answer is "..\..\z" because there is no available option "../z" (which is correct on Linux) and the separator char used in all options is '\\' (Windows), not '/' (Linux). Nonetheless maybe it is worth noticing here that "x\\y" is a valid filename on Linux. A quick proof: the following code outputs "x\y" on Linux, not "y" (as on Windows):

Code: Select all

System.out.println(Paths.get("x\\y").getFileName());
This means in my opinion that the individual explanations for each option are correct on Windows, but incorrect on Linux. For instance the example in the explanation for the option "..\..\z": "x\y + ..\..\z" resolves to "x\y/..\..\z" on Linux, not to "z" (as on Windows), because both "x\\y" and "..\\..\\z" are valid filenames on Linux:

Code: Select all

Path p1 = Paths.get("x\\y");
Path p2 = Paths.get("..\\..\\z");
System.out.println(p1.resolve(p2).normalize());
In contrast to the individual explanations for options, the main explanation for this question seems to be valid for both types of operating systems: Windows and Linux.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 36 guests