Re: java bean program
On Sep 4, 10:01 am, Andreas Leitgeb <a...@gamma.logic.tuwien.ac.at>
wrote:
Lew <no...@lewscanon.com> wrote:
public void setUrl(String url)
{
if(url!=null)
this.url=url;
This 'if' test has no net effect. If you pass 'null' to the method,
'this.url' will be null either way. Notice that your error was a
NullPointerException. Coincidence?
Wrong! If you call setUrl with a null argument, then
this.url remains what it was before. When doing the
assignment unconditionally, an eventually previously
set url would be overwritten with null.
You are right in general. In the particular case of the OP's
situation, this was the first time the logic was invoked, so "what it
was before" was 'null'.
catch(ClassNotFoundException e)
{
System.out.println(e);
Never use 'System.out.println()' for error reporting in web apps.
Huh? Doesn't it show up in (e.g.) tomcat's log then?
What's so bad about it?
Loggers are much better. Loggers maintain thread context for you,
don't incur the call overhead every time they're used unless the
logging level calls for it, and can vary the logging level at
deployment without recompilation, among their advantages.
System.out.println() (nor System.err.println()) has none of those
advantages.
In fact, my mistake was limiting the rule to web apps. Generally, use
System.out to display information to the user, not for logging.
--
Lew