Page 1 of 1

About Question enthuware.ocpjp.v8.2.1822 :

Posted: Thu Aug 09, 2018 8:19 am
by ArpRokz
I have these questions..

1) Does getNameCount() starts counting from 0 or 1 ?

2) Does it include root when counting ( \ or C:) ?

3)When I run this code in eclipse:

Code: Select all

public class test11
{
  public static void main(String args[])
  {
      Path p1 = Paths.get("photos\\..\\beaches\\.\\calangute\\a.txt");   
      
      Path p2 = p1.normalize(); 
      Path p3 = p1.relativize(p2);
      Path p4 = p2.relativize(p1);
      

      System.out.println(p1);
      System.out.println(p2);
      System.out.println(p3);
      System.out.println(p4);

      System.out.println(     p1.getNameCount()+" "+p2.getNameCount()+" "+     p3.getNameCount()+" "+p4.getNameCount());
  }
}
It ouputs:

photos\..\beaches\.\calangute\a.txt
beaches\calangute\a.txt


6 3 1 1

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

Posted: Thu Aug 09, 2018 11:10 am
by admin
1. "count" is the number of elements, so "starting from 0 or 1" is not a valid question here. If there are no elements then the count will be 0. It is the "index" that starts with 0. i.e. index of the first element is 0. If there are 10 elements, the index of the first element is 0 and last is 9.

2. The given path components are separated using the path separators and those components are counted. So, the question whether it includes root or not is not relevant here

3. Please read the explanation. It explains this output.

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

Posted: Sun Aug 04, 2019 12:53 pm
by BinSlayer
Hi. Did they change the implementation in-between JDK 8 and JDK 11?
Indeed when running the code on JDK 11 it will print out 6 3 1 1.
It would seem to my naked eye that JDK 11 prefers normalizing any path before using it. Could you confirm that I got this right? Thanks.

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

Posted: Sun Aug 04, 2019 11:59 pm
by admin
Yes, it looks like they changed the implementation in Java 11.
The answer has been updated with relevant information.
thank you for your feedback!
Paul.

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

Posted: Sat Aug 10, 2019 9:29 am
by sir_Anduin@yahoo.de
I´m at version 1/11 and still get the anser 6 3 9 9

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

Posted: Sat Aug 10, 2019 11:31 am
by admin
Fix was in 1.13.
Please update your question bank file.

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

Posted: Mon Aug 12, 2019 12:04 pm
by sir_Anduin@yahoo.de
It says that I am up to date:
Unbenannt.PNG
Unbenannt.PNG (14.04 KiB) Viewed 5320 times
Build : 20190622
ETSV Version: 20190423

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

Posted: Tue Aug 13, 2019 12:09 am
by admin
It will notify now.