About Question enthuware.ocpjp.v8.2.1524 :

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

Moderator: admin

Post Reply
schchen2000
Posts: 106
Joined: Mon Mar 28, 2016 11:36 pm
Contact:

About Question enthuware.ocpjp.v8.2.1524 :

Post by schchen2000 »

Hi,

I've got a related question on this question.

The following excerpt is from here: https://docs.oracle.com/javase/7/docs/a ... CopyOption...)
public static long copy(InputStream in, Path target, CopyOption... options) throws IOException

Copies all bytes from an input stream to a file. On return, the input stream will be at end of stream.

By default, the copy fails if the target file already exists or is a symbolic link. If the REPLACE_EXISTING option is specified, and the target file already exists, then it is replaced if it is not a non-empty directory. If the target file exists and is a symbolic link, then the symbolic link is replaced. In this release, the REPLACE_EXISTING option is the only option required to be supported by this method. Additional options may be supported in future releases.
If the REPLACE_EXISTING option is specified, and the target file already exists, then it is replaced if it is not a non-empty directory.
Based on this quote, the parameter "Path target" in the above copy method can be a file as well as a folder.

Is that correct?

If it is indeed a folder, then the folder must be empty before the copy with REPLACE_EXISTING can take place successfully.

Is that true?

Thanks.

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

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

Post by admin »

Yes, that is correct. You should try it out and see what happens.
-Paul.
If you like our products and services, please help us by posting your review here.

schchen2000
Posts: 106
Joined: Mon Mar 28, 2016 11:36 pm
Contact:

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

Post by schchen2000 »

admin wrote:Yes, that is correct. You should try it out and see what happens.
-Paul.
Thanks, Paul.

Schmichael

schchen2000
Posts: 106
Joined: Mon Mar 28, 2016 11:36 pm
Contact:

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

Post by schchen2000 »

Hi Paul,

One more question if you don't mind. This one is different from the one I asked earlier.
public static Path copy(Path source, Path target, CopyOption... options)                  throws IOException Copy a file to a target file. This method copies a file to the target file with the options parameter specifying how the copy is performed. By default, the copy fails if the target file already exists or is a symbolic link, except if the source and target are the same file, in which case the method completes without copying the file. File attributes are not required to be copied to the target file. If symbolic links are supported, and the file is a symbolic link, then the final target of the link is copied.
What does the following quote mean?
If symbolic links are supported, and the file is a symbolic link, then the final target of the link is copied
Does it mean the contents of an ACTUAL file pointed by the "Path source" symbolic link, NOT the contents of the symbolic link, will be copied into the destination file, namely Path target?

In other words, let's say the "Path source" symbolic link parameter points to a.txt, which contains "Hello World!". When everything is said and done eventually, the file with the name "target" will contain "Hello World!"

Is that correct?

If that is true, Path target will be a regular file, NOT a symbolic link.

Is that correct?

Thanks.

Schmichael

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

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

Post by admin »

That sounds correct but you should verify this by running a test program.
If you like our products and services, please help us by posting your review here.

schchen2000
Posts: 106
Joined: Mon Mar 28, 2016 11:36 pm
Contact:

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

Post by schchen2000 »

admin wrote:That sounds correct but you should verify this by running a test program.
Hi,

Thank you very much. I thought about it but then this question was asked out of curiosity. I believe the exam MAY cover what a symbolic link mean and what they are but building a symbolic link on the exam? I'm not sure if it's out of the scope of this exam.

I've found how to build a symbolic link in Java here: https://docs.oracle.com/javase/tutorial ... ml#symLink

So, in a sense, for a variety of reasons plus building a symbolic link myself to answer my own question was dissuading me to try to write code and test it on my own in order to quell my curiosity.

Once again, thanks a lot. If the person who gave the earlier answer is in the States, Happy 4th of July weekend to you. I understand EnthuWare is based in India?

Schmichael

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

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

Post by admin »

It is out of the scope for the exam.
Yes, we are in India but our director is based in US. Some of our authors are based in US as well. One author is from Netherlands.
Happy 4th of July to you too :)
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

AungKNyar
Posts: 5
Joined: Mon Jan 14, 2019 11:16 pm
Contact:

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

Post by AungKNyar »

I don't understand why this choice with try block doesn't work:

try(Files.copy(p1, p2, StandardCopyOption.REPLACE_EXISTING))
{    Files.delete(p1); }

but this one works, could someone please explain?

Files.copy(p1, p2, StandardCopyOption.REPLACE_EXISTING);
Files.delete(p1);

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

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

Post by admin »

What do you mean by "does not work"? What is the error (compiler or other) do you get when you try to compile/run the code?
If you like our products and services, please help us by posting your review here.

AungKNyar
Posts: 5
Joined: Mon Jan 14, 2019 11:16 pm
Contact:

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

Post by AungKNyar »

By does not work, I meant to say that it's not the correct answer. I'm using a Mac computer so I couldn't test it on Eclipse.

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

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

Post by admin »

You don't need eclipse or any ide to run a test program. In fact, we discourage people from using an IDE while preparing for the certification exam.
Just compile and run it from command line.

try with resource takes a resource that implements AutoCloseable as an argument. While Files.copy returns a long.
If you like our products and services, please help us by posting your review here.

bvrulez
Posts: 33
Joined: Sat Feb 15, 2020 12:44 am
Contact:

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

Post by bvrulez »

admin wrote:
Tue Jan 15, 2019 11:06 am
try with resource takes a resource that implements AutoCloseable as an argument. While Files.copy returns a long.
What does it have to do with returning a long?

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

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

Post by admin »

bvrulez wrote:
Mon Feb 17, 2020 2:41 am
admin wrote:
Tue Jan 15, 2019 11:06 am
try with resource takes a resource that implements AutoCloseable as an argument. While Files.copy returns a long.
What does it have to do with returning a long?
Well, the code, in response of which the statement that you have quoted was written, has the Files.copy call in a try with resource statement. You can't put a long in a try with resourse because it expects an AutoCloseable. long is not an AutoCloseable.
If you like our products and services, please help us by posting your review here.

bvrulez
Posts: 33
Joined: Sat Feb 15, 2020 12:44 am
Contact:

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

Post by bvrulez »

Ah, sorry, now I got it. The return type must implement AutoCloseable, not the method copy() or the class Files. Thanks for the fast reply!

Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests