Question

I’m preparing for OCPJP7 exam on these days. I got two questions and accepting answers. First one is relevant to java and other one is about exam achievements.

import java.nio.file.*;
class Test13{
   public static void main(String arfd[]){

       Path a = Paths.get("D:\\OCPJP7\\programs\\..\\NIO2\\SRC\\.\\Subpath.java");
       a=a.normalize();
       System.out.println(a);

   }

}
  1. According to the above code segment, I was expected the output as “D:\OCPJP7\programs\NIO2\SRC\Subpath.java” But it is not. It provides “D:\OCPJP7\NIO2\SRC\Subpath.java

    As I know normalize() removes any redundant elements from the given path including single dot and double dot. Then why it removes \programs\ element?

  2. In order to be an Oracle Certified Professional, Java 7 Programmer, we have to sit for two exams;

    OCA -JP (Oracle Certified Associate, Java 7 programmer).

    Java SE 7 programmer.

    As I know we can achieve both exams in any order. So I’m intended to do first Java SE 7 programmer and then OCA.

    My question is what will offer by the Oracle, after passing both exams. Are they offering two certificates for both exams? or one certificate for both? And anything else?

Was it helpful?

Solution

As I know normalize() removes any redundant elements from the given path including single dot and double dot. Then why it removes \programs\ element?

.. refers to the the parent directory. In other words, /programs brings you forward and /.. brings you back.

The Javadoc of Path#normalize() states

If a ".." is preceded by a non-".." name then both names are considered redundant (the process to identify such names is repeated until it is no longer applicable).

So \\programs\\.. is redundant and removed.

I can't answer your second question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top