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 B&S final word on trim() 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 "B&S final word on trim()" Watch "B&S final word on trim()" New topic

B&S final word on trim()

Kate Jackson

Joined: Jan 12, 2010
Posts: 13

Does these sound ok (ok in terms of I did it and passed ) ?

1. Is it safe to assume that leading and/or trailing whitespace characters in create/update/find are not allowed, I throw a IAE in such case. My implementation of Data class is rather defensive. If I write " Kate " it's either saved as it is or rejected as invalid and not silently changed to "Kate".
- trailing whitespaces - padding with spaces in db eliminates usage of these
- leading whitespaces - there are none in supplied db file + I don't have implement my own trimTrailing(String) utility method, just a simple trim() does the trick when records are loaded from db. On the other hand goodness knows what the customer wants, perhaps it's safer to allow leading whitespaces to be entered.

2. In GUI I also trim values in search fields (setText(getText().trim())) when user presses the Search button. Since they are internally trimmed for search the user should be aware of that, right ?

3. In GUI empty name/location criteria matches only empty field in db. The * matches any value (translated to null), escape character is \. The * only works as a wildcard if query contains no other characters (requirement for full search matches only).

thanks in advance,

Roel De Nijs

Joined: Jul 19, 2004
Posts: 8364

1. I also used trim() when creating/updating records

2. I just used the search values as provided, no trimming here (and/or internally)

3. My search method is a lot simpler: a null value is ignored, otherwise you have a match if the value starts with the search criterium. You need at least 1 hit to have a match.

SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
I agree. Here's the link:
subject: B&S final word on trim()
It's not a secret anymore!