File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes about parameter check Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "about parameter check" Watch "about parameter check" New topic
Author

about parameter check

LianGuang Wang
Greenhorn

Joined: Mar 26, 2006
Posts: 11
in my exam,i need implent these interface:
public void update(int recNo, String[] data, long lockCookie)
public int create(String[] data)
do i need check the parameter String[] data to ensure is legal?
thanks!

[edited title to reduce volume! -BG]
[ April 29, 2006: Message edited by: Barry Gaunt ]
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
In some methods I do just to show I can (mainly in the constructor of my wrapper class), in most I don't.
For that I use assertions, as such errors should only happen during application testing and never during deployment (if they do happen after deployment it means there has been no testing, not my problem).

When you get the wrong number of elements in the array, it's a programmer error by definition, which you would want to give a nasty error so the person making the error will fix it.


42
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Unless you are following Bertrand Meyer's Design By Contract concept you should certainly do a sanity check on your input parameters. Make sure refrences are not null, record numbers are not negative. Lock cookies would be checked at a later stage.

If you are following design by contract, the caller would have checked them.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Eventually of course there's a check, way down in the method that creates the actual write buffer for example:


The find method will work just fine if the number of fields passed doesn't match the number of fields in the record.
If less, the rest of the record is not matched, if more the rest of the arguments are ignored.

I was under the impression that the question related to the user interface rather than the backend.
I take some liberty there because it's more or less a single logical unit.
Checks there I do only on the boundaries where someone could plug in enhancements (like a new search dialog) and classes designed for reuse in other clients.
LianGuang Wang
Greenhorn

Joined: Mar 26, 2006
Posts: 11
thanks everybody!
in my requirement "Portions of your submission will be analyzed by software....."
so i'm afraid that the interface may be tested under all circumstances! for example,some field must be number;some field must be "Y" or "N";and how should i deal with this condition!
BTW:the interface can't be change so throws a new checked Exception is not allowed! the last way is throwing a RuntimeException,but it's crazy for validate a input parameter!
thanks
[ May 01, 2006: Message edited by: LianGuang Wang ]
Josephx Rainerd
Greenhorn

Joined: Apr 27, 2006
Posts: 12
Hi

I was wondering if it makes sense to validate parameters in the Table (or TableModel) itself. Since Table comes with editors, some sanity checks can be automatically taken care of.(Sun wants JTable!)
It Table OK's the data, it makes to the database, no more checks.

Thanks
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Depends on how you use your JTable. In my implementation it's strictly for displaying data only, I've disabled all editing functions (while adding other things to make it look nice, like colour coding of records with different status).
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: about parameter check
 
Similar Threads
DuplicateKeyException
DuplicateKeyException
passing in a file from the command line
Doubt on Varargs and overriding
generic method