About Question enthuware.ocpjp.v7.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
renatumb
Posts: 47
Joined: Mon Apr 08, 2013 7:55 pm
Contact:

About Question enthuware.ocpjp.v7.2.1552 :

Post by renatumb »

I am confused with this question, because in its options/answer,
new OpenOption[]{StandardOpenOption.READ, StandardOpenOption.DELETE_ON_CLOSE}
This is an invalid combination.
But READ and DELETE_ON_CLOSE to be an invalid combination, depend on where they are used...
For example, in the method below, they can be used together

Code: Select all

Files.newByteChannel( Path, StandardOpenOption )


So, I think the value(s) of StandardOpenOption is totally dependent of the method where it will be used..

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

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

Post by admin »

You are right. This seems to be valid combination.
Unfortunately, even though the API documentation for StandardOptionOption does not mention which combinations are valid and which are not, the exam includes questions on this aspect. "Depends on the implementation" is indeed correct, but it is not an option.

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

laura90_m@yahoo.com
Posts: 3
Joined: Sun Apr 14, 2013 12:02 pm
Location: Romania
Contact:

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

Post by laura90_m@yahoo.com »

For this question, in the answer is:
new OpenOption[]{StandardOpenOption.READ, StandardOpenOption.SYNC}
This is an invalid combination.
I tested this for
Files.newByteChannel(Paths.get("test.txt"), StandardOpenOption.READ, StandardOpenOption.SYNC);
where the file "test.txt" exists. It seems to work, no exception thrown.

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

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

Post by admin »

Yes, this is a problem. We were trying to provide a simple way for the candidates to answer this type of questions but the issue is that the API does not clearly specify which combinations are valid and which are not. Further, they work on some machines and not on others.

So we have now added this statement to the explanation that it is not really possible to determine with certainity which combination will work and which will not work.

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

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

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

Post by The_Nick »

READ AND SYNC
Ideally, this should be an invalid combination but it works in some cases.
Should I thick it as a valid answer or not in the real exam?

The_Nick

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

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

Post by admin »

It is really not possible to suggest what to do this such as case. Your guess is as good as any others. But if since it works fine on your platform, you have a strong ground to mark it as valid.

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

jowfornari
Posts: 3
Joined: Sun Sep 28, 2014 11:05 am
Contact:

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

Post by jowfornari »

How come READ and DELETE_ON_CLOSE is a valid combination? (2nd option)

Even the question explanation states that "Thus, READ and TRUNCATE_EXISTING (or WRITE, APPEND, or DELETE_ON_CLOSE) cannot go together."

Thanks in advance.

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

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

Post by admin »

Please read this discussion from the top. It is mentioned above.
If you like our products and services, please help us by posting your review here.

codecodecode67
Posts: 14
Joined: Sun Dec 06, 2015 2:15 pm
Contact:

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

Post by codecodecode67 »

It really depends on what you're using to open the file with, so I believe this question should be changed. If you're using a BufferedReader, WRITE is an invalid option to add. If you're using a BufferedWriter, READ is an invalid option to add. READ & SYNC may work in some cases for BufferedReader but will never work for BufferedWriter. Whereas APPEND & CREATE_NEW works for BufferedWriter given that the file does not exist (marked as a wrong answer in this question).

What I'm getting at is that with the current phrasing of the question - disregarding whether a Writer or a Reader is being used - the valid combinations cannot be determined.

Please let me know what you think.

Thanks

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

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

Post by admin »

The Javadoc API descriptions of these constants do not mention that valid combinations depend on how the file is used.

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

codecodecode67
Posts: 14
Joined: Sun Dec 06, 2015 2:15 pm
Contact:

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

Post by codecodecode67 »

That may be so but if you look at the underlying code:

Code: Select all

BufferedWriter br = Files.newBufferedWriter(writeFile, Charset.forName("UTF-8"), new OpenOption[] {StandardOpenOption.APPEND, StandardOpenOption.CREATE_NEW});
If you go into method newBufferedWriter, then into method newOutputStream from the below snippet:

Code: Select all

Writer writer = new OutputStreamWriter(newOutputStream(path, options), encoder);
then newOutputStream again from the below snippet:

Code: Select all

return provider(path).newOutputStream(path, options);
you'll see the below code is used every time you create a BufferedWriter using java.nio.Files:

Code: Select all

public OutputStream newOutputStream(Path path, OpenOption... options)
        throws IOException
    {
        int len = options.length;
        Set<OpenOption> opts = new HashSet<OpenOption>(len + 3);
        if (len == 0) {
            opts.add(StandardOpenOption.CREATE);
            opts.add(StandardOpenOption.TRUNCATE_EXISTING);
        } else {
            for (OpenOption opt: options) {
                if (opt == StandardOpenOption.READ)
                    throw new IllegalArgumentException("READ not allowed");
                opts.add(opt);
            }
        }
        opts.add(StandardOpenOption.WRITE);
        return Channels.newOutputStream(newByteChannel(path, opts));
    }
where the default options are CREATE and TRUNCATE_EXISTING, which are not added if at least one option is added by the user, and WRITE is always added as an option regardless. Plus you can see that it fails if it detects READ is being used.

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

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

Post by admin »

Assuming that you have quoted code from Java standard library classes, they are free to make changes in the code as long as they stick to what is guaranteed by the their Javadoc API description. So making inferences by looking inside the code is not a good idea, imho.

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

jelofka
Posts: 6
Joined: Tue Aug 30, 2016 5:47 am
Contact:

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

Post by jelofka »

Hi,

if new OpenOption[]{StandardOpenOption.READ, StandardOpenOption.SYNC} is OK for
v7.2.1552, it should be ok for v7.2.1551 as well or at least somehow modify one of these two questions (or explanations) in order to avoid inconsistency. Just a suggestion.

KR
Matjaz

sir_Anduin@yahoo.de
Posts: 62
Joined: Fri Aug 07, 2015 2:16 pm
Contact:

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

Post by sir_Anduin@yahoo.de »

I agree,
the questions enthuware.ocpjp.v7.2.1551 and enthuware.ocpjp.v7.2.1552 has a different validity for the same option.

Post Reply

Who is online

Users browsing this forum: No registered users and 96 guests