Page 1 of 1

About Question enthuware.ocpjp.v8.2.1599 :

Posted: Tue Oct 11, 2016 3:07 pm
by johnny_pl
In this question, we have:

Code: Select all

        Path p1 = Paths.get("photos\\goa");
        Path p2 = Paths.get("\\index.html");
        Path p3 = p1.relativize(p2);
        System.out.println(p3);
When I'm trying this code out on my Linux machine from IntelliJ, I get the following result:

Code: Select all

../\index.html
However, you mark the answer "java.lang.IllegalArgumentException will be thrown" as the correct one with the explanation "Note that if one path has a root (for example, if a path starts with a // or c:) and the other does not, relativize cannot work and it will throw an IllegalArgumentException."

From my point of view, the path "\\index.html" does not contain a root element. Only if I change this path to "/index.html" than I get this Exception.

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

Posted: Tue Oct 11, 2016 10:19 pm
by admin
The exam may contain code with paths in *nix or windows format. You will need to recognize that paths containing forward slash are *nix paths while paths containing \\ are windows paths and select the answer based on that platform. In this case, for example, you should assume that the code is running on windows and not on *nix.

HTH,
Paul.