File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Valid / Invalid Records Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Valid / Invalid Records" Watch "Valid / Invalid Records" New topic
Author

Valid / Invalid Records

Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Hi Guys,

When the insturctions say
1 byte flag. 00 implies valid record, 0xFF implies deleted record


does this mean that I can use the int value of 0 for a valid record and the int value 1 for an invalid record?


OCPJP 6, OCMJD
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

Why would you want to store an invalid record?
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4908
    
  10

That's correct! "invalid" as in "this record does not exist, it's deleted, so please don't show it to the user".


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4908
    
  10

Matthew Brown wrote:Why would you want to store an invalid record?

Because that's part of the assignment. If the record is deleted, you have to write a flag to the file to indicate that this record is deleted, so you don't return it as a match when a search is executed.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

Maybe I misunderstood. I interpreted the question as meaning "invalid" as distinct from "deleted" - i.e. three states. Otherwise, what's the value 1 got to go with it?
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Roel De Nijs wrote:That's correct! "invalid" as in "this record does not exist, it's deleted, so please don't show it to the user".


Why do the instructions say 0 and 0xFF instead of 0 and 1?

I know there are 0-255 possible values between 0 and 0xFF and I think that is what is confusing me.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4908
    
  10

Yes, it's not an invalid record (as "in wrong data" or "incomplete"). It's just to indicate that a record is deleted and should be ignored when searching/retrieving
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4908
    
  10

Glen Iris wrote:Why do the instructions say 0 and 0xFF instead of 0 and 1?

You can't assign 0xFF to a byte. But if you force it (just use a cast) and just print it to the console, -1 is printed.

I just glanced back to my project and I definitely used 1 to indicate a deleted record. But I don't think that's the most important part of the assignment
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

I notice that none of the records in my database file have anything in the validity field.

I was thinking of initially assuming they are all valid and set them all to 1 when I first read them in. I would also write to the db file to mark them as valid records if they are not explicitly marked as invalid

Can you guys please share your thoughts on this?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

Glen Iris wrote:I notice that none of the records in my database file have anything in the validity field.

I was thinking of initially assuming they are all valid and set them all to 1 when I first read them in. I would also write to the db file to mark them as valid records if they are not explicitly marked as invalid

Since 0 is supposed to mean "valid", doesn't that mean that they are all flagged as valid already, and you don't need to assume anything? And so, if that's the case, there's no need to write anything back (unless the records change).

Again, I feel I'm missing something (and I apologise if I am), but you seem to be making a distinction between having "nothing" in the validity field, and having zero. Surely these are the same case?
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Matthew Brown wrote:
Glen Iris wrote:I notice that none of the records in my database file have anything in the validity field.

I was thinking of initially assuming they are all valid and set them all to 1 when I first read them in. I would also write to the db file to mark them as valid records if they are not explicitly marked as invalid

Since 0 is supposed to mean "valid", doesn't that mean that they are all flagged as valid already, and you don't need to assume anything? And so, if that's the case, there's no need to write anything back (unless the records change).

Again, I feel I'm missing something (and I apologise if I am), but you seem to be making a distinction between having "nothing" in the validity field, and having zero. Surely these are the same case?


this is my question really. Is it safe to assume this?
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4908
    
  10

I assumed all records in the database file are valid
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Valid / Invalid Records
 
Similar Threads
NX: about delete record...
Invalid Flag Question
All my records are deleted ?
NX:[URLyBird]How to use the specified Data File Format?
URLyBird: How do I read in Deleted Flag?