About Question enthuware.ocpjp.v7.2.1584 :

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

Moderator: admin

Post Reply
caa4444
Posts: 2
Joined: Mon Dec 23, 2013 2:20 pm
Contact:

About Question enthuware.ocpjp.v7.2.1584 :

Post by caa4444 »

It says the correct answer is ..\..\..\..\index.html, but shouldn't it just be ..\index.html?

My thinking:
Path 1 simplifies
c:\\personal\\.\\photos\\..\\readme.txt -> c:\\personal\\photos\\..\\readme.txt
c:\\personal\\photos\\..\\readme.txt -> c:\\personal\\readme.txt

or is it different because Path 1 isn't simplified?

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

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

Post by admin »

Yes, relativize doesn't canolicalize/simplify the paths.
Try it out.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

caa4444
Posts: 2
Joined: Mon Dec 23, 2013 2:20 pm
Contact:

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

Post by caa4444 »

ok. thanks for the help!

rolandlensink
Posts: 7
Joined: Thu Mar 16, 2017 7:44 am
Contact:

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

Post by rolandlensink »

I think the answer is ok ... relativize() does not normalize the path and the answer seems to be logical.

But when I do p1.resolve(p1.relativize(p2)).normalize() ... the answer is c:\index.html ... what is not a logical answer ...

When I first normalize p1 and then do the same ... the answer is c:\personal\index.html (what should be the logical answer)

So, I think your explanation about the answer c:\ is not correct ...

If you do a relativize without first normalizing, there are 4 '..\' it means it goes 4 levels up is the directory tree (and there is still one in p1), so this means that you go up to the root ...
There are 2 '..\' too much, because of not normalizing the path ...

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

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

Post by admin »

I am not sure I understand your point. Can you please the paste the complete and exact the statement from the explanation that you think is incorrect?

Also, please paste the complete code that you are trying out.
If you like our products and services, please help us by posting your review here.

rolandlensink
Posts: 7
Joined: Thu Mar 16, 2017 7:44 am
Contact:

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

Post by rolandlensink »

Maybe I do something wrong, but my point is that the explanation you give at the question is not correct.
I used the following code:
Path p4 = Paths.get("C:\\personal\\.\\photos\\..\\readme.txt");
Path p5 = Paths.get("C:\\personal\\index.html");
Path p6= p4.relativize(p5);
System.out.println(p6);
System.out.println(p4.resolve(p6));
System.out.println(p4.resolve(p4.relativize(p5)).normalize());

System.out.println("");
Path p14 = p4.normalize();
Path p16= p14.relativize(p5);
System.out.println(p14);
System.out.println(p16);
System.out.println(p14.resolve(p16));
System.out.println(p14.resolve(p16).normalize());
My point is, that you first have to normalize the path(s) before relativizing ....

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

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

Post by admin »

I am still not clear on which part of the explanation you think is wrong. Where does the explanation claim that you have to or don't have to normalize?

There is no requirement imposed by the API that you have to normalize. You can relativize and resolve without normalizing also. Of course, the results in both the cases may be different. That depends on what your original path is composed of.

The only thing that is promised by the API (as mentioned in the explanation also) is, "for any two normalized paths p and q, where q does not have a root component, p.relativize(p.resolve(q)).equals(q)". Thus, if your paths are not normalized, the results may vary.

The explanation is only talking about how to work out the results of applying resolve and/or relativize methods.

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

runnerdave
Posts: 12
Joined: Mon Jan 30, 2017 2:58 pm
Contact:

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

Post by runnerdave »

try this version if you are in linux or mac:

Code: Select all

//linux version
		Path p12 = Paths.get("/c/personal/./photos/../readme.txt");
		Path p13 = Paths.get("/c/personal/index.html"); 
		Path p14 = p12.relativize(p13); 
		System.out.println(p14);

Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests