File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: create() 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 "NX: create()" Watch "NX: create()" New topic

NX: create()

joe black
Ranch Hand

Joined: Dec 03, 2003
Posts: 103
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.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11778

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

    The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
    joe black
    Ranch Hand

    Joined: Dec 03, 2003
    Posts: 103
    How should I keep track of the new record's record number?
    I agree. Here's the link:
    subject: NX: create()
    It's not a secret anymore!