• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OutputStream question

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Come across this question in an exam, anyone knows the answer?
If write(0x01234567) is called on an instance of OutputStream, what will be written to the destination of the stream? Select one write answer.
(a) The bytes 0x01, 0x23, 0x34, 0x45 and 0x67, in that order.
(b) The bytes 0x67, 0x45, 0x34, 0x23 and 0x02, in that order.
(c) The byte 0x01
(d) The byte 0x67
(e) None of the above
If the answer is none of the above, how does the write method write to the destination of the stream? Thanks.
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kasey,
Try the following code:

If you are in a linux environment, go to the shell an type "od -t x1 out", this will produce the following output:
0000000 67
0000001
That is to say, as expected the answer is "(d) the byte 0x67", because the write(int) method of the OutputStream class only writes to the underlying stream the lower byte of the input integer.
Hope this helps
Eduard
 
reply
    Bookmark Topic Watch Topic
  • New Topic