About Question enthuware.ocpjp.v8.2.1552 :

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

Moderator: admin

Post Reply
lws963
Posts: 2
Joined: Thu Sep 29, 2016 7:06 am
Contact:

About Question enthuware.ocpjp.v8.2.1552 :

Post by lws963 »

Hi,

My problem with these questions about invalid OpenOption combinations is, that IMO the reason because the JavaDoc does not explicitly mention which combinations are invalid is that there are no global invalid combinations. It depends on the operation (read or write), and whether a file exists or not.

For example answer 4 states, that
new OpenOption[]{StandardOpenOption.APPEND, StandardOpenOption.CREATE_NEW}
This throws java.lang.UnsupportedOperationException: 'APPEND' not allowed.
This is true for an InputStream, but the Files.newBufferedWriter method accepts this combination if the file does not exist. The combination InputStream + APPEND is invalid, not the the combination of the the APPEND + CREATE_NEW.

Also answer 5:
new OpenOption[]{StandardOpenOption.READ, StandardOpenOption.SYNC}
Ideally, this should be an invalid combination (because when a file is opened for READ, there is nothing to synch) but it works.
The Files.newBufferedWriter method throws a java.lang.IllegalArgumentException: READ not allowed but it works with an InputStream. Again, the combination itself is not invalid, it just depends on the operation.

or did I miss something here?

Thanks

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

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

Post by admin »

You may be right. However, the exam does have questions that require you to figure out valid combinations without the context on the operation.
I think a candidate will have to make a best guess to answer such questions.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

lws963
Posts: 2
Joined: Thu Sep 29, 2016 7:06 am
Contact:

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

Post by lws963 »

Thanks for the info. Let's hope I won't have to guess....

BTW, I did some research, and I found only 4 cases, but they are all operation dependent:
- the Files.newInputStream() method throws UnsupportedOperationException for WRITE and APPEND.
- the Files.newBufferedWriter method throws IllegalArgumentException for READ and the combination of APPEND + TRUNCATE_EXISTING.

thanks,
Tamas

Post Reply

Who is online

Users browsing this forum: No registered users and 212 guests