So the database file provided in my SCJD assignment has its first two bytes reserved as a magic cookie at the very beginning of the file. What is this magic cookie for? I currently don't see a use for it. Am I missing something?
The magic cookie identifies your file as a database file in the reqired format for your application. Your app should check this cookie in the startup process so it can throw around exceptions if it got fed an unknown file format. If the cookie is correct, you can still encounter a corrupted file, but if it is incorrect, you know for sure the file is bad.
Well, since the Magic Number that the database already has is, in my case, 257, I assumed that this is the right Magic Cookie (Magic Number in my case). When I first open the database file I check if this is the value found; if it is, than it's OK, otherwise, I don't proceed.
So, this number is the first thing that appears in the .db file. It indeed does not appear in the assignment, and all we know is that it identifies whether a particular file is valid or not. Since the valid value is not mentioned, and my .db file has this value (257), I assumed that this value is the correct one. By the way, I hardcoded this value. This is the first thing of the .db file. As soon as you open it, call the readInt() method of your RAF object, and you'll find out the magic number of your database!