The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S: Writing of records 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 "B&S: Writing of records" Watch "B&S: Writing of records" New topic

B&S: Writing of records

Zeng Wei Chu

Joined: Dec 05, 2007
Posts: 27
Hi all, have a question regarding the writing of records into the database file.

The instruction states that all text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field.

However from what I observed in the database file, the text values fields are not null terminated, instead they are padded with spaces.

So now I have two choices now, one is to pad with spaces for each field when its less than its maximum length, or null terminate it.

Which method is more appropriate? Padding with spaces makes the subsequent created records more consistent with existing records. But instruction states that they should be null terminated.

Any advice is greatly appreciated!


David Coppens

Joined: Oct 24, 2007
Posts: 17
I followed Sun's example and add extra spaces to fill the fields.
This allows my read method to be simpler, because I don't have to check for null characters and can simply read a fixed amount of bytes all at once. Furthermore, it does not violate the requirements, because all fields are full and thus no null characters are needed.

There is, however, one design issue that you should mention if you take this approach. You assume that the data file that came with the assignment will always be padded with spaces and no null characters. In theory, Sun could use another file that does include null characters, because they stated this in the requirements, and that would break my code.

SCJA (94%)<br />SCJP (84%)<br />SCWCD (84%)
Zeng Wei Chu

Joined: Dec 05, 2007
Posts: 27
Hi David, thanks for clarifying my doubt. I will stick with the method to pad with spaces. Will add this into my assumptions list.

I agree. Here's the link: http://aspose.com/file-tools
subject: B&S: Writing of records
Similar Threads
Null terminated
B&S Question on instructions
null terminate fields?
B&S database file format
Null terminated strings?