Page 1 of 1

About Question enthuware.ocpjp.ii.v11.2.1596 :

Posted: Tue Aug 04, 2020 10:42 am
by mspronk
For the question, what does this print:

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);
        
The correct answer (D) shows ..\..\index.html
However I believe (and so does IntelliJ) that it should be ..\index.html (which is not an option)

Re: About Question enthuware.ocpjp.ii.v11.2.1596 :

Posted: Tue Aug 04, 2020 10:44 am
by admin
Please try it from command line and mention the JDK and OS details.

Re: About Question enthuware.ocpjp.ii.v11.2.1596 :

Posted: Tue Aug 04, 2020 10:58 am
by mspronk
Trying this file:

Code: Select all

import java.nio.file.Path;
import java.nio.file.Paths;

class Scratch {

  public static void main(String[] args) {
	  Path p1 = Paths.get("\\personal\\readme.txt");
	  Path p2 = Paths.get("\\index.html");
	  Path p3 = p1.relativize(p2);
	  System.out.println(p3);
  }
}
from command line gives me:
../\index.html
using openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.6+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.6+10, mixed mode)
on MacOS

Re: About Question enthuware.ocpjp.ii.v11.2.1596 :

Posted: Tue Aug 04, 2020 11:00 am
by mspronk
Interestingly, if i change the source to *nix style path names, it DOES work correct:

Code: Select all

	  Path p1 = Paths.get("/personal/readme.txt");
	  Path p2 = Paths.get("/index.html");
results in
../../index.html

Re: About Question enthuware.ocpjp.ii.v11.2.1596 :

Posted: Tue Aug 04, 2020 11:26 am
by admin
With official Oracle's JDK (1.8 as well as 11.0.2), it produces the output as given in the question. i.e. ..\..\index.html

Strongly suggest you to use Oracle's JDK and command line tools for the purpose of the exam.