my dog learned polymorphism
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes if must use DataInputStream ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "if must use DataInputStream ?" Watch "if must use DataInputStream ?" New topic

if must use DataInputStream ?

Along huang
Ranch Hand

Joined: Feb 09, 2004
Posts: 72
In instruction, I can't fully understand the intention about accessing db file.

the sentance is "All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes".

Should I use DataInputStream and DataOutputStream to access record from db file ?

but I find it is not convenient to use those classes, I rather use RandomAccessFile class.


SCJP1.4 SCJD 2<br />SCEA(In progressing)
Serkan Yazici
Ranch Hand

Joined: Apr 24, 2004
Posts: 33
Hi Along,

I think what the instructions want to make clear is don't worry about the endian format for the numbers (In other words, readShort/readInt/writeShort/etc specified in DataOutput and DataInput interfaces and implemented in DataInputStream and DataOutputStream classes will work fine).

Since RandomAccessFile implements both interfaces as well, using RandomAccessFile is fine too. In fact, if Java supported multiple implementation inheritance; RandomAccessFile would probably directly extend DataInputStream and DataOutputStream classes and leave read/write methods intact

-- SCJP 1.4 (98%), SCJD (98%), SCWCD (96%), OCA Dev (97% avg.), SCBCD (97%), SCJP 1.5 BETA (90%)<br />-- OCP Dev (maybe), MCDBA (probably) SCEA (eventually)<br />-- Haven't tried Firefox yet? Free, open, secure, fast, tabified, and slick!<br />-- <a href="" target="_blank" rel="nofollow"></a>
Along huang
Ranch Hand

Joined: Feb 09, 2004
Posts: 72
thank you for response.

It is said that I can use RandomAccessFile to access the db file,but I'm not sure whether doing so deviate Sun's intention,as the instruction expressly say to use DataInputStream.

Mike Keller

Joined: Mar 22, 2004
Posts: 9
They aren't telling you to implement DataInputStream, they are just describing the format of the numbers. DataInputStream and RandomAccessFile both get their functionality reading numbers from the DataInput interface. Don't sweat it.

Michael Keller, BS,SCJP
I agree. Here's the link:
subject: if must use DataInputStream ?
It's not a secret anymore!