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

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

Moderator: admin

Post Reply
mspronk
Posts: 4
Joined: Tue Aug 04, 2020 10:37 am
Contact:

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

Post 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)

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

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

Post by admin »

Please try it from command line and mention the JDK and OS details.
If you like our products and services, please help us by posting your review here.

mspronk
Posts: 4
Joined: Tue Aug 04, 2020 10:37 am
Contact:

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

Post 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

mspronk
Posts: 4
Joined: Tue Aug 04, 2020 10:37 am
Contact:

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

Post 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

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: marpiva and 38 guests