File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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="" target="_blank" rel="nofollow">Java and Web Development</a>
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33124

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


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

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, 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.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
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 )
I agree. Here's the link:
subject: Size of serialized classes
It's not a secret anymore!