About Question enthuware.ocpjp.v7.2.1608 :

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

Moderator: admin

Post Reply
dieterdde
Posts: 19
Joined: Wed May 25, 2016 4:33 am
Contact:

About Question enthuware.ocpjp.v7.2.1608 :

Post by dieterdde »

This one caught me off guard/confuses me. I thought initially that both paths p1 & p2 were relative paths because neither start with a root, which is c: on windows and / on unix, right?

But given that assumption, p1.resolve(p2) would have been simply tacking on the relative p2 path onto p1 which would be: \\photos\\vacation\\yellowstone

However given that none of the options had this answer, and knowing that when you pass an absolute path into the argument, it will return the absolute argument, I concluded that \\ means these are absolute paths.

Hence resolve returning the path passed being \\yellowstone which turns into \yellowstone as a String output.

But I see here Paul is saying these paths are not absolute paths but relative paths. This seems to be confirmed, as in my testing, i get null for Paths.get("\\test").getRoot()

I'm very confused here, if these are truly not absolute paths (which getRoot() confirms), why isn't p2 then not simply tacked onto p1?

In the K&B book for OCA/OCP7 prep, there is an example like this:

Path relative = Paths.get("dir");
Path file = Paths.get("Model.pdf");
relative.resolve(file) -> dir/Model.pdf
file.resolve(relative) -> Model.pdf/dir

Both the relative path and the file are relative paths, right? Why do they get tacked on and not in the mock exam question?

Given that "\\test" is a relative path (as I understand from this thread), is it any different from just "test" ?

Cheers!
Dieter

EDIT, in fact on my system, Mac OS X I get this:
Path p1 = Paths.get("\\test");
Path p2 = Paths.get("\\er");
p1.resolve(p2) -> \test/\er

What the.... ?

aPerson
Posts: 17
Joined: Fri Aug 12, 2022 10:19 am
Contact:

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

Post by aPerson »

Correct me if I'm wrong, but I believe the "argument to resolve" in the explanation refers to p1, whereas "argument" refers to p2 (in case it confuses anyone else). Also, I made the following overview to help me understand:

"c:\\photos\\vacation" + "" --> c:\photos\vacation
"c:\\photos\\vacation" + "yellowstone" --> c:\photos\vacation\yellowstone
"c:\\photos\\vacation" + "\\yellowstone" --> c:\yellowstone
"c:\\photos\\vacation" + "c:\\yellowstone" --> c:\yellowstone

"\\photos\\vacation" + "" --> \photos\vacation
"\\photos\\vacation" + "yellowstone" --> \photos\vacation\yellowstone
"\\photos\\vacation" + "\\yellowstone" --> \yellowstone
"\\photos\\vacation" + "c:\\yellowstone" --> c:\yellowstone

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

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

Post by admin »

Yes, this is a bit weird.
1. Since the given paths use \ (i.e. backslash), it is fair to assume that windows paths are being used. Although it is possible to have such paths on Unix based systems also, for the purpose of the exam, consider only paths contains / (i.e. forward slash) to be unix paths.
2. On windows, paths starting with root such as c:\ are absolute paths. Therefore, in the given question, neither of the paths are absolute paths.

However, it looks like when you start a windows path with a \, the implementation is considering it as an absolute path. This is proven by the following code:
(I am running the code from c:\temp directory)

Code: Select all

   Path p2 = Paths.get("yellowstone");
   System.out.println(p2.toAbsolutePath()); //prints C:\temp\yellowstone

   p2 = Paths.get("\\yellowstone");
   System.out.println(p2.toAbsolutePath()); //prints C:\yellowstone
This explains the result of p1.resolve(p2) in the given question.

The bottom line is that for the purpose of the exam it is best to use unix based paths for experimentation and learning how these methods work and not waste time on this. We will update this question accordingly.
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 37 guests