Page 1 of 1

OCA Wrong Answer - Test 5 Question 33

Posted: Wed Nov 13, 2024 11:27 am
by macetini
While answering questions for OCP cert came across this question:

Code: Select all

What will the following code fragment print?

        Path p1 = Paths.get("c:\\personal\\.\\photos\\..\\readme.txt");
        Path p2 = Paths.get("c:\\personal\\index.html");
        Path p3 = p1.relativize(p2);
        System.out.println(p3);
The correct answer was :

Code: Select all

..\..\..\..\index.html
But on my machine (eclipse Ide, jdk13) i get this:

Code: Select all

..\index.html
Makes sense to me. Am I doing something wrong?

Re: OCA Wrong Answer - Test 5 Question 33

Posted: Wed Nov 13, 2024 10:46 pm
by admin
This question is not from OCA. It is from OCP.
Are you using OCP 8 question bank?

1. Java >=11 normalizes paths before computing relativize. Since you are using Java 13, you are getting a different answer.
2. As per JavaDoc of the relativize method:
Where both paths have a root component then it is implementation dependent if a relative path can be constructed.
Depending on which version of the exam you are studying for the answer would be different. The explanation in the OCP java 11 question bank notes this point. But if you are using OCP 8 question bank then the given answer is correct.

Re: OCA Wrong Answer - Test 5 Question 33

Posted: Thu Nov 14, 2024 4:00 am
by macetini
Yes, I meant OCP 8 question bank. I will change the jdk version to 8. Thanks for the quick replay.