wood burning stoves
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes About the read and find method 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 "About the read and find method" Watch "About the read and find method" New topic

About the read and find method

Jack Horner

Joined: Feb 22, 2005
Posts: 6
Hi ,
I hava sevral question about my find and read method.

1.the read method.

(1) because the read method only can throw RecordNotFoundException. so i define a
unchecked Exception called DataBaseAccessException .then i turn the IOExcetion into the unchecked Exception(DataBaseAccessException).Is it right?
like this:

(2) My read method not only can read undeleted record but also can read deleted record.In other words the read method don't kown the record is a deleted record or not. is it right?

2.the find method
(1) Can I reuse the read method in the data class.
(2) Given i can reuse the read method. Can i turn the RecordNotFoundException throwed by read method into DataBaseException.
is it reasonable?
(3) could you give me some advice about the method?

my find method

[Andrew: removed some trailing tabs from the code block that were causing horizontal scrolling]
[ August 09, 2005: Message edited by: Andrew Monkhouse ]
Lara McCarver
Ranch Hand

Joined: Dec 09, 2003
Posts: 118
I don't have my exam instructions right in front of me, but I think they made it pretty clear that if a record is past the end of file or deleted, the read method is supposed to throw a RecordNotFound exception, *not* return an invalid record.

And for the find method, I believe you need to throw a RecordNotFound exception if there are no matches.

As for your code example, your try/catch block is too wide. If there is a single record that has been deleted, you will get a RecordNotFound exception, at which point you... throw an exception and exit the method? The right thing to do is to eat the exception, realizing that it just means it's a deleted record, and then move on to testing the next record.

Finally, it could be just me, but I think it's a little risky to turn in code with a labelled break statement. I was just reading Core Java, which seems to be a semi-official book on how to use Java, and in the section where they describe labelled break, there is a comment about how of course you would never do this... I would get rid of the need for a labelled break by adding a helper method to compare 2 records, or maybe to read a record and then compare it.
[ August 09, 2005: Message edited by: Lara McCarver ]
Tom Henricksen
Ranch Hand

Joined: Mar 23, 2004
Posts: 136

Lara is this closer to what you mean for the find method?

Jack what are you doing in the isStartWith() method?
I just replaced it with string.startWith(string) as I am unsure what you have there.

[ August 11, 2005: Message edited by: Tom Henricksen ]
[ August 11, 2005: Message edited by: Tom Henricksen ]
I agree. Here's the link: http://aspose.com/file-tools
subject: About the read and find method
It's not a secret anymore!