Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Initialization attributes

 
Isaac Ferguson
Ranch Hand
Posts: 837
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64711
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instance variables in a servlet must be avoided at all costs. Your servlet is not thread-safe!
 
Junilu Lacar
Bartender
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic