GeeCON Prague 2014*
The moose likes Java in General and the fly likes Size of serialized classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Size of serialized classes" Watch "Size of serialized classes" New topic
Author

Size of serialized classes

dave taubler
Ranch Hand

Joined: May 15, 2001
Posts: 132
I'm using serialized ValueObject classes as return values from some stateless session EJBs. In other words, I'm sending classes that are basically just data containers across the network, and to go from JVM to JVM, they have to be serialized. Obviously, I want to keep these classes as small as possible, so that not too much data is being transmitted, thus potentially hampering performance.

So my question is whether anyone know if adding methods to these classes actually increases their serialized sizes. Assume that the methods I am considering adding do not necessitate any more members variables. An example might be that one of my classes has a few different variables that might represent its "name". If I add a complex getDisplayName() method that uses a bunch of logic to figure out for a given context what its "name" is, will I have increased the size of that class' serialized form?

Thanks in advance!


Dave Taubler<br />Specializing in <a href="http://taubler.com/articles/" target="_blank" rel="nofollow">Java and Web Development</a>
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30586
    
154

Originally posted by dave taubler:
So my question is whether anyone know if adding methods to these classes actually increases their serialized sizes.

Dave,

Adding methods does not affect the serialized size. It does affect the size of the compiled .class file, but that's separate.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

And you may write a serialized class to disk, modify it, save it again, and then compare yourself.


http://home.arcor.de/hirnstrom/bewerbung
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
It helps to understand this stuff if you get picky about nomenclature.
You do NOT "write a serialized class to disk" you serialize an instance of a class. The size of this file will depend on the serialized instance variables and has nothing to do with the methods.

All of the class methods live in the .class file as created by the compiler.

Bill (being picky )
 
GeeCON Prague 2014
 
subject: Size of serialized classes