Java and .NET - Java serialization vs XML

To recap - yesterday we all learned that Java and .NET can interop using Java serialization. J# includes this capability, so serializing a J# class and shipping it over to a Java (JDK 1.4.1) app actually works. The opposite direction also works.

The interesting question from yesterday was, how does the performance of interop using Java serialization compare to the performance of interop using XML serialization? The answer I found: binary serialization is "a little bit" faster.

I modified the sample from yesterday's post, to do both Java (binary) serialization and XML serialization, so you can compare the results. Using either binary or XML serialization, I was able to send 1000 messages of 1000+ bytes through MQ Series, in "about" 3 seconds on my machine, using a single-threaded receiver. The binary format took about 2.5 seconds, and the XML format typically took 3.2 seconds.

Screen shot:

You can see from the above that the first run of either binary or xml serialization takes longer. I suppose this is because of JIT compilation that is happening on the server side and possibly on the client-side as well. The first run of the xml serialization took extra long.

I tried using JAXB to do the Java XML serialization, but failed. Kept getting ClassCastExceptions, and it totally mystified me. I googled everywhere but could find no joy. So .... I did the obvious thing and downloaded Apache's XMLBeans. This is a pretty nifty gadget for your Java toolbox. It works like the XML Serialization in .NET, but I it has some nifty features that .NET v1.1 does not have.

Tangentially: I hear from Dare's blog that David Remy, formerly of BEA and a member of the XMLBeans team, has recently come to Microsoft. Woohoo!

In any case, using XMLBeans, the .NET and Java sides can each serialize an instance into a document that conformed to an XML Schema. XMLBeans was pretty simple. Just to be clear, I did not use XMLBeans on the J# side - I used .NET's built-in XML serialization.

Anyway, y'all can get the sample code and try it out yourself.

Get the sample

InteropTest-MQ-with-xml-and-ser-2004Dec10.zip