This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Servlets & Beans

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a bean to store the result of a SQL query. When creating a bean to hold this info should I initialise the various fields in the declaration or is this overkill given?
eg:
public class MyBean {
private String mydata = "";
-OR-
public class MyBean {
private String mydata;
Thanks
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If every field is always going to be filled by the query there is no need to initialize them. In any case I doubt you could measure the difference in execution speed.
Bill
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All Class variables are initialized to their default values. In case of Strings they are initialized to null. One reason to initialize the variables to "" is if you want to avoid getting any null values if you try to get a variable that has not been set. If that is not a problemthen you can leave them unitialized.
Parag
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
If you are going to use all the data initialized or if all the fields are going to initialized on querying DB. Then assigning the empty string might help you to check some condition like checking stringname.equals("").
But it will create extra object which means extra server resource utilization. So better initialize to 'null' rather then to empty string.
-arun
 
Hoo hoo hoo! Looks like we got a live one! Here, wave this tiny ad at it:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!