This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes what is the magic cookie value? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "what is the magic cookie value?" Watch "what is the magic cookie value?" New topic

what is the magic cookie value?

joel smither
Ranch Hand

Joined: Jan 01, 2005
Posts: 31
In my urlybird dev exam project, there is something called a "magic cookie" value in the database file.

What is the purpose fo this piece of information, am I exprected to do something with it programmatically?

Thanks in advance.
Eric Chang
Ranch Hand

Joined: Jan 27, 2004
Posts: 113
There is a previous thread about this here:

You might find it useful.
joel smither
Ranch Hand

Joined: Jan 01, 2005
Posts: 31
I'm still not clear on what should be done with this cookie value.

I get the impression from reading previous threads that the cookie value is used to determine that a file is valid database file or not.

So what should I do in my application? Does every valid database file use the SAME cookie? If so I guess I could check to make sure the file has the appropriate cookie value when I first open it up for access. Is this the right thing to do?
Eric Chang
Ranch Hand

Joined: Jan 27, 2004
Posts: 113
You can do whatever you want with it. There is no MUST to do anything with the cookie value. Some people (like me) have decided to hardcode it in and use it to verify a database file. I'm sure there are other people who chose not to do anything with it (I was about to do that, but I figured one line of extra code couldn't hurt).
Sean Gildea
Ranch Hand

Joined: Jul 01, 2004
Posts: 81
I just verified it was equal to 00 00 in hex , since those are the first 2 hex numbers in the file.

Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11757

Hi everyone,

If you are not already aware of this, there are multiple assignments, and multiple versions of the assignments. Some of the variations in the versions of the assignments do include changes to the database structure. For example, some databases have a two-byte "deleted" flag, while others have a single-byte "deleted" flag. There are many more differences as well.

So even if two candidates are working on the contractors assignment, the database formats may be completely different. In such a case, though, the cookie values will be different.

I personally feel that you must validate the cookie value, as not all the database structural changes will be catered for in the meta data.

Regards, Andrew

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
I agree. Here's the link:
subject: what is the magic cookie value?
It's not a secret anymore!