Page 1 of 1

About Question enthuware.ocpjp.v7.2.1090 :

Posted: Fri Apr 18, 2014 3:02 am
by bptoth
Maybe it's just me, but for me the third option (with BufferedOutputStream) produces a zero length file :?:

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

Posted: Fri Apr 18, 2014 6:30 am
by admin
The code for //close open streams is not shown but you should always flush a buffered stream before closing.
HTH,
Paul.

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

Posted: Wed Jun 10, 2015 2:27 am
by rocky_bgta
1)DataOutputStream dos = new DataOutputStream(os);
dos.write(1);
A file of size 4 bytes will be created.

2)os.write(1);
A file of size 1 byte will be created.

3)BufferedOutputStream bos = new BufferedOutputStream(os);
DataOutputStream dos = new DataOutputStream(bos);
dos.write(1);
A file of size 1 byte will be created.

4)os.writeInt(1);
A file of size 4 bytes will be created.

Answer say option 2 and 3 are correct answer, But my question if option 3 is correct then option 1 should also correct.
Please explain me.
Thanks

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

Posted: Wed Jun 10, 2015 5:13 am
by admin
Why do you think so?

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

Posted: Wed Jun 10, 2015 6:42 am
by rocky_bgta
because i use same object type reference that is:
DataOutputStream XXX

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

Posted: Wed Jun 10, 2015 10:15 am
by admin
Right, since both are using DataOutputStream, you cannot have file size of 4 bytes in one and 1 byte in another. Both cannot be correct.

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

Posted: Thu Feb 25, 2016 3:40 am
by rianne
I've got a completely different question:
The book I am using to study for the exams, clearly states that you only have to know Reader and Writer classes/methods for the exam, and that if you see Streams, the question will be about serialization...
(I am using the OCA/OCP Java SE7 Programmer I & II Study Guide by Kathy Sierra and Bert Bates)
Then why are there questions like this in the mock exams? Is my book wrong?

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

Posted: Thu Feb 25, 2016 4:46 am
by sumanenthu
I also have the same question. Are those topics are in syllabus in details?

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

Posted: Thu Feb 25, 2016 10:37 am
by admin
We add questions to our question bank on such topics only because some candidates have reported getting question on such topics.
The real exam is quite dynamic and they change their questions often. We keep an eye on feedback from candidates who take the exam and make changes to our question bank accordingly.

I can't really comment on any particular but but it is a fact that books are static. They can't be changed once they are printed and that is why they cannot track the changes in the exam as well as we can.

HTH,
Paul.

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

Posted: Thu Nov 26, 2020 6:26 am
by FiskSMK
Response 4 seems having error in explanation:

os.writeInt(99);
A file of size 4 bytes will be created.
OutputStream does not provide methods for writing primitives.
It writes bytes only. Therefore, this will not compile.

We have write(int b). Valid explanation would there is no such method.

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

Posted: Thu Nov 26, 2020 8:48 am
by admin
The explanation is talking about methods such as writeInt, writeChar, writeBoolean etc.
The write(int b) method does not write an int to the file. It writes only the byte part of the int.

The explanation has now been enhanced to make it clear.