Source is represented by p1 while destination is represented by p2 in this problem.By default, Files.move method attempts to move the file to the target file, failing if the target file exists except if the source and target are the same file, in which case this method has no effect. Therefore, this code should throw an exception because a.java exists in the target directory.
"....failing if the target file exist...."
It did not say the target file exists by the same name as the source file or different name from the source file. If the target file exist, move fails. That's what it says by the bold text above. There is an exception, i.e. in case of source and destination files being the same, there won't be a failure. In case of source and destination files being the same, move() method has no effect, i.e. it's like running a no-op.
Given all that information and analysis, why did you say
"Therefore, this code should throw an exception because a.java exists in the target directory."????
When source and destination files are the same, shouldn't move() method have no effect? Why throw an exception?
I fully understand why java.nio.file.NoSuchFileException is thrown due to running deletion after move.
I tried to understand this topic by reading Oracle documentation. It's so verbose and a lot of rubbish so I finally resorted to asking the question on your site.
Many thanks for your time.
Schmichael