File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 321
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: 4419
    
    5

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: 60041
    
  65

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: 4419
    
    5

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: http://aspose.com/file-tools
 
subject: Initialization attributes
 
Similar Threads
a question about boolean?
JAxb binding problem
Assigning jsonobject to java class having one to many relationship
Retrieve DataFeed API
DataFeed Problem