aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes (B&S)My Data.java and read() ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "(B&S)My Data.java and read() !" Watch "(B&S)My Data.java and read() !" New topic
Author

(B&S)My Data.java and read() !

Saheed Adepoju
Ranch Hand

Joined: Jun 23, 2004
Posts: 267
Hi all
First of all, if i violate any of the JavaRanch policies by dropping my Data.java's constructor and also my read() method for your advice and tips, pls remove appropriately and i apologise; but i just wanna know if my read() is on track and appropriate! I use a cache:


I dont know if this procedure is sufficient for a read() method? Also i dont know if my Data.java constructor is appropriate? Thanks! :roll:

[Andrew: removed code that is irrelevant to the discussion]
[ December 30, 2005: Message edited by: Andrew Monkhouse ]

Saheed Adepoju<br />SCJP 1.4<br />SCJD (B&S..In progress)
Ali Hussain
Ranch Hand

Joined: Jun 19, 2005
Posts: 211
For exception handling, I would have done something like this:

try {
recordLength = raf.readInt();
} catch(IOException io) {
throw new DataAccessException("I/O Error", io);
}

Note io is given as an argument to DataAccessException. In this way, exception chaining (getCause) can be used later.


- SCEA, SCJD, SCBCD, SCWCD, SCMAD, SCJP, ICAD (WebSphere), Lotus Principal CLP, Lotus CLP, Lotus CLS
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11523
    
100

Hi Saheed
First of all, if i violate any of the JavaRanch policies by dropping my Data.java's constructor and also my read() method for your advice and tips, pls remove appropriately and i apologise;
This is dangerously close to having all code removed, however I have decided to leave it for now.

I think you have far too much code posted for getting many comments - it just becomes too much for others to read and make comments on. You would be better breaking it down to smaller sections. While I got rid of many methods and variables that were not germaine to your desired discussion on the read() methods and the constructor, it could have been pared down even further. Probably it would have been best to have a post that only discussed the constructor (and only had those methods and variables necessary for that discussion), then another post that only discussed the read method with a comment that global variables are initialized in the constructor (possibly with a pointer back to the original thread).

I don't think there is much value in having both a Javadoc comment and an inline comment:Speaking of dbName - why is it a global variable? Do you use it outside of the constructor and it's associated openDataFile() method?

Your read() method has a very small window of oportunity for a record to be deleted between the validation of the record and the conversion back into a String[].

Regards, Andrew


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

Joined: Jun 23, 2004
Posts: 267
Hi
Thanks Ali Hussein and Andrew for your insights! I apologise and would make necessary adjustment to posts i send next time! I see your point about the dbName, it's best made a local variable! I also see your point as regards the read()! I will look thru it again! I have modified the code to have a method to check for the validity of the file now! Thanks for your input!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: (B&S)My Data.java and read() !