• Post Reply Bookmark Topic Watch Topic
  • New Topic

null and serialization  RSS feed

 
chandru ram
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a question on serialization:
If an object say a String Object whose value is null is serialized.
how will it be represented in the stream.

If there are 2 Strings whose values are null and empty string.which one will give a better performance when serialized. {i.e.) does having a value as null gives good performance while serializing.
Thanks in advance,
Chandru
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Chandru, we don't have many rules at the Ranch, but we do have some naming ones we like everyone to abide by. Click here, and then click on the My Profile link to change your name (you need a first and a last).
As far as your question, what type of stream are you talking about? For instance, if you are using an ObjectInput/OutputStream, then serializing null will cause null to come out on the other end.
As far as performance, I couldn't imagine there being much difference over using null versus an empty String. The empty String still creates an object, so you're actually serializing/deserializing something, but it's a really negligible something.
 
chandru ram
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jason,
note that i have changed my name according to the rules.
consider the containers of the application servers.The values are serialized before passing to remote clients.in these cases does using null have a performance gain.

thanks
chandru ram


Howdy Chandru, we don't have many rules at the Ranch, but we do have some naming ones we like everyone to abide by. Click here, and then click on the My Profile link to change your name (you need a first and a last).
As far as your question, what type of stream are you talking about? For instance, if you are using an ObjectInput/OutputStream, then serializing null will cause null to come out on the other end.
As far as performance, I couldn't imagine there being much difference over using null versus an empty String. The empty String still creates an object, so you're actually serializing/deserializing something, but it's a really negligible something.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, I doubt you'll see a significant increase in performance, even when sending to remote clients. If you are truly concerned with the micro or nano second level, then perhaps you will see some gain. Otherwise, I personally wouldn't worry about it.
At work, we send objects between clients (mostly applets) and backend servers (through a servlets input/output streams). We send null if there is no data to send for whatever reason.
If you were dealing with Collections, I personally don't like sending null, I like sending an empty Collection. Just makes sense. However, distinguishing between an empty String or a null is usually a nit I don't pick
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!