File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Initialization attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Initialization attributes" Watch "Initialization attributes" New topic

Initialization attributes

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 752

I am using some attributes and I think that inicialize them would be a good idea

My code looks like

Is inicialize itr a good idea?

For example something like


Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

Java already does that for you implicitly. Explicitly initializing to null is redundant. If you initialize it to some other value, that's a different matter. Also, why do you use String for things that are named 'xxxDate' and 'xxxFlag' -- dates should be declared as Date and flags are usually boolean. Use the data type that's closest to the way the value is naturally represented. Using String may be expedient for display purposes but for calculations and logic, it makes coding more difficult and convoluted.

Junilu - [How to Ask Questions] [How to Answer Questions]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63857

Instance variables in a servlet must be avoided at all costs. Your servlet is not thread-safe!

[Asking smart questions] [About Bear] [Books by Bear]
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

Bear is right. I didn't notice that you were extending HttpServlet until he pointed it out. Don't do that, Servlets can service multiple threads concurrently.
I agree. Here's the link:
subject: Initialization attributes
It's not a secret anymore!