user2895564
user2895564

Reputation: 21

Is serialized file platform independent?

In an interview I was asked if a serialized file i.e. a .ser file platform independent or dependent and why? I told him that .ser files are platform independent but I dont know the answer. Please let me the know answer.

Upvotes: 1

Views: 1270

Answers (2)

zslevi
zslevi

Reputation: 409

Depends on how you define a platform. It's OS and JVM vendor independent (assuming you explicitely declare the "serialversionUID"). On the other hand, standard Java library classes might change, so that they will not be deserializable with future JVM versions. (e.g. Swing classes)

But if you need to communicate with .Net, you have to use XML serialization (JAXB,XStream etc.), which is truly platform independent.

See also:

Is java object serialization compatible between 1.5 and 1.6

Upvotes: 0

Mike Thomsen
Mike Thomsen

Reputation: 37526

Yes. They are tied to the JVM and the JVM's internal operations are platform independent. Aside from platform-specifics about how JIT-compiled code looks when running on the CPU and things like that, there's no difference between compliant JVMs regardless of hardware or OS. So from your perspective, Java is Java is Java across all of those platforms until you have Java that references native resources (code, hardware, etc.)

Upvotes: 5

Related Questions