About Question enthuware.ocpjp.v7.2.1596 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

About Question enthuware.ocpjp.v7.2.1596 :

Post by The_Nick »

Hi,
You say in the explanation quoting the javadoc:
Where this path and the given path do not have a root component, then a relative path can be constructed.

A relative path cannot be constructed if only one of the paths have a root component.

Where both paths have a root component then it is implementation dependent if a relative path can be constructed.
In your question your paths are:
 Path p1 = Paths.get("\\personal\\readme.txt");
Path p2 = Paths.get("\\index.html");
 Path p3 = p1.relativize(p2);
 System.out.println(p3);
Both p1 and p2 are starting with: "\\".
then quoting again from the explanation:
A relative path cannot be constructed if only one of the paths have a root component.
And it's true because if you remove "\\" from either of the 2 paths, it's going to throw an exception.

However, after it says:
Where both paths have a root component then it is implementation dependent if a relative path can be constructed.
In your question both have "\\" does it imply that it's implementation dependent?

Thanks in advance.

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1596 :

Post by The_Nick »

Another question related, I have tried the following:

Code: Select all

Path path = Paths.get("\\indeed\\try");
		Path path1 = Paths.get("\\home\\user\\Desktop\\Enthu\\try1.txt");
		System.out.println(path.relativize(path1));
I got this output: ../\home\user\Desktop\Enthu\try1.txt

What is ../?!?

Thanks in advance.
Sorry about all these questions, it's just that I have got the exam on Friday and I am getting a little "what if there is this question.. "

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

Re: About Question enthuware.ocpjp.v7.2.1596 :

Post by admin »

These are relative paths on Windows because we are using \\ (which is basically \) and not /. \ is used on Windows while / is used on *nix.

Also, since there is no option that says there will be an error (or implementation dependent), you can assume that they are relative paths and the question is not trying to test the border case where both the paths have root component.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1596 :

Post by The_Nick »

At the end of all "\\" is a root component or not? or only c:\\ is a root component.
A relative path can contain a root component, or only an absolute path can?
I think that there is a bit of confusion between path separator and root component.
Root component should be c: and path separator "\\".
Waiting to know what you think about it.
Thanks in advance.

The_Nick.

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

Re: About Question enthuware.ocpjp.v7.2.1596 :

Post by admin »

Technically, yes, it is a root component. If you do getRoot() on p1, it should return "\".

So in that sense, yes, you are right, relativize would be implementation dependent
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1596 :

Post by The_Nick »

Moreover,

on WINDOWS:
Path path = Paths.get("photos\\vacation"); // windows
Path path1 = Paths.get("yellowstone");
Path path2 = path.relativize(path1);
System.out.print(path2);

output: ../yellowstone

on LINUX
Path path = Paths.get("photos/vacation"); // unix
Path path1 = Paths.get("yellowstone");
Path path2 = path.relativize(path1);
System.out.print(path2);

output: ../../yellowstone

Apparently even with two relative paths it's system dependent..

Which one is going to be used by Oracle windows or unix? I don't think is fair doing such things though, what about one prepares on unix and then finds out that at the exam one of the possible solution is ../yellowstone.. (windows) while actually in unix the corresponding result would be actually ../../yellowstone.

Thanks a lot in advance. I would hate to miss a point because of this inconsistency.

The_Nick.

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

Re: About Question enthuware.ocpjp.v7.2.1596 :

Post by admin »

Are you sure you are getting

../yellowstone

on Windows? I just tried it and got

..\..\yellowstone

I don't think the output should be different on Unix and Windows in this case.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1596 :

Post by The_Nick »

Yep you right, I have tried the code of windows on linux, hence "\\" was not considered a FileSeparator.

Thanks.

jordanglassman
Posts: 4
Joined: Tue Oct 28, 2014 2:11 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1596 :

Post by jordanglassman »

Why does

Code: Select all

index.html
"cancel" with a double dot? Doesn't this imply that

Code: Select all

index.html
is a directory?

In other words, these both return the same thing, but my guess was that filenames would be ignored in the calling path since you don't usually talk about a location relative to a file.

Code: Select all

        Path p1 = Paths.get("/personal/readme.txt");
        Path p2 = Paths.get("/index.html");
        Path p3 = p1.relativize(p2);
        System.out.println(p3);

        p1 = Paths.get("/personal/readme.txt/");
        p2 = Paths.get("/index.html/");
        p3 = p1.relativize(p2);
        System.out.println(p3);
Output:

Code: Select all

../../index.html
../../index.html

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

Re: About Question enthuware.ocpjp.v7.2.1596 :

Post by admin »

No, the path doesn't really care whether it is a file or a directory. It is only when you try to open/use a file as a directory or viceversa that you get an exception.
In fact, you can actually create a directory named index.html!
If you like our products and services, please help us by posting your review here.

insider
Posts: 29
Joined: Wed Apr 17, 2013 9:22 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1596 :

Post by insider »

I suggest to explicitly add a couple more points to the explanation since this question has apparently caused confustion among test takers including me:
1) resolve(), relativize() and normalize() all operate on strings and don't check for actual file paths;
2) Path doesn't care whether segment is a file or a directory.
Because apparently people try to use their existing file system experience. It might cause confusion that the answer to go from "\personal\readme.txt" to "\index.html" is "..\..\index.html". The last segment is often perceived as a file thus it seems unnatural to ".." on it.

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

Re: About Question enthuware.ocpjp.v7.2.1596 :

Post by admin »

Added. Thank you for your feedback!
Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests