aspose file tools
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


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Initialization attributes" Watch "Initialization attributes" New topic
Author

Initialization attributes

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 557
Hi

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



Thanks

Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 6264
    
  15

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
Marshal

Joined: Jan 10, 2002
Posts: 63026
    
  69

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 6264
    
  15

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.
 
jQuery in Action, 3rd edition
 
subject: Initialization attributes
 
It's not a secret anymore!