public int create(String data) throws DuplicateKeyException Can someone give me a general idea of what would be a solid way to implement this method? Also, should I use NIO, and if so where? And should this method be synchronized? Thanks.
Hi Joe, It would be much better if you presented some of your ideas first, and then others can comment on them. But as a general guideline: You have two options here:
add a new record to the end of the database, ignoring any deleted records. (The instructions only tell us that the create() method can possibly reuse a deleted record, not that it must )
search for a deleted record, then overwrite that record with the newly created record.
You can use NIO if you like (and if you have never used it before, this could be a good project for you to learn how to use it). If you are going to use NIO, then I would suggest that you use it for all your I/O work on the database - don't try and limit it to one or two methods. As for whether this method should be synchronized or not: that depends . Are you going to have only one instance of the Data class, or multiple instances? Are you going to have your I/O operations in the Data class itself or in a helper class? The answers to these questions may change where you need to put synchronization, and whether you synchronize an entire method or just a block within a method. Regards, Andrew