Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Initialization attributes

 
Isaac Ferguson
Ranch Hand
Posts: 1045
3
Java Netbeans IDE Spring
  • 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
Marshal
Posts: 10158
122
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
Posts: 65542
110
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
Marshal
Posts: 10158
122
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.
 
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!