Archive for the ‘java’ Category
Thursday, September 14th, 2006
OK, I know this sounds like another one of those “a white horse is not a horse” arguments, but from my observation on the Spring forums and other blog reading, some clear distinction between the semantics of a Spring singleton and a classical Java singleton has become much necessary. The overloaded term has caused quite some confusion, especially for someone who has just started picking up Spring. more…
Posted in java, spring | 4 Comments »
Friday, September 1st, 2006
Fire up your favorite IDE, close all the files that are already open, and start implementing an individual feature of your project, just how you normally would go about it. Along the way, remember not to close any editor window (or tabs, or buffers, you got the idea) once it’s been opened. When you are done, count the Number of Open Files you have got so far - that’s the NoOF index for that particular feature. Repeat the process, and you have the average NoOF index of your project, which I think really tells something about the complexity of the framework/architecture your project employs. more…
Posted in java | No Comments »
Wednesday, August 30th, 2006
We all know that this is bad:
JAVA:
-
try {
-
// ...
-
} catch (DaoException e) {
-
// do nothing.
-
}
But some of us (namely the dude who wrote the code that drove me crazy trying to troubleshoot today) apparently didn't know this was almost equally bad:
JAVA:
-
try {
-
// 200 lines of code with many dao calls.
-
} catch (DaoException e) {
-
throw new AppException(e.getMessage());
-
}
What's wrong with that is there is no way to tell at exactly which point DaoException was thrown, since the original stack traces are lost. So, my fellow Java programmers, please, please always do:
JAVA:
-
try {
-
// 200 lines of code with many dao calls.
-
} catch (DaoException e) {
-
throw new AppException(e.getMessage(), e); // <--- always pass along the cause!
-
}
The only time should you be using the message-only constructor is when AppException is the root cause itself.
Posted in java | 2 Comments »
Thursday, August 17th, 2006
YUI Connection Manager throws this error when the ajax url passed to it is invalid (invalid as in, like, "I forgot to set the value!"). What makes it more obscure is it prints out the page url, which often looks alike, if not the same, the ajax url:
uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest.open]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: http://localhost:8080/myapp/foo.do :: anonymous :: line 0" data: no]
Posted in java, web-design | No Comments »
Sunday, August 13th, 2006
Yeah, right, keep using String.split(",") to parse CSV files and one of these days you'll run into some comma hidden inside a pair of quotes - like how I did while trying to import some Excel-generated CSV file into a database. So I sat down and wrote this CSVParser with java.util.regex - it actually turned out to be a fun brain teaser to make a CSV parser that's able to parse any CSV files as defined by the Specification. To cope with the huge files I was importing, an additional requirement was to be able to parse in stream mode, instead of having to read the entire file into the memory first. That seemed to be easy at first but became quite a hassle because of the "a new line character can appear in a double-quoted field" part of the Spec.
Posted in java | 4 Comments »
Tuesday, August 8th, 2006
This might sound philosophical and irrelevant, but hear me out - the biggest problem I have with checked exceptions is that they are way too prescriptive. When we say "checked exceptions force themselves to be handled," that's an understatement of the prescriptiveness. What's worse is actually that checked exceptions impose this forcement on the immediate caller. more...
Posted in java | 3 Comments »
Saturday, July 22nd, 2006
So I am trying to use Hibernate to map a class hierarchy with table-per-hierarchy mixed with table-per-subclass. more...
Posted in hibernate, java | No Comments »
Tuesday, July 11th, 2006
One AJAX page I've been playing with has this UI flow that emulates a desktop form dialog - the user clicks on a link, a modal dialog shows up with a usual form, which the user fills out and submits to the server. Now, a successful response from the server can be one of these: if there are any form validation errors, the response is the same form annotated with the error message(s), in this case the response should be used to refresh the dialog. If there are no errors, the dialog is closed, and the response from the server should contain some content to update the area above the original link the user clicked on. more...
Posted in java, microsoft, web-design | 3 Comments »
Thursday, July 6th, 2006
I've been whining for quite a while to some friends and coworkers about how checked exceptions have ruined and will continue to ruin our codebase, because it leads those lesser disciplined developers to doing blindly either "throws Exception" or "catch(Exception)". So naturally I found it very interesting reading Paul Watson's blog on Checked Exceptions, and the articles collected there. Just wanted to echo to those.
Posted in java | No Comments »
Thursday, July 6th, 2006
I have been wanting to give postgresql a try for some time. The reasons are manifold - the clean coming BSD license for a starter, a somewhat more standard compliant SQL engine compared to MySQL and even some commercial products, etc. But my postgresql experience takes a blow right in the face at the first attempt to start the server - more...
Posted in LAMP, java | 3 Comments »