0

I am developing an application in Java, where I have some classes, like Person and Company. All these classes have some instances e.g.

public class Person{
      private String firstName;
      private String lastName;
      private String mail;

     //more code..
}

So in some point I create an Object type of Person, which I want to save it for future use. I am new to this, so I have this question. Should I use Object serialization or should I save it in XML format? I realize that an XML format has its advantages that's why I am asking (If I want to save it in XML format, I use XMLEncoderclass right?) Which one should I use?

yaylitzis
  • 5,354
  • 17
  • 62
  • 107
  • 1
    Read about JAXB ([a tutorial](https://jaxb.java.net/tutorial/)). A tool from JDK (6+) called `xjc` would build you POJOs from an XSD file with dead simple setters/getters, and serialization support. Maybe it's what you need. – 9000 Dec 17 '14 at 18:20
  • possible duplicate of [Java Serialization vs JSON vs XML](http://stackoverflow.com/questions/11102645/java-serialization-vs-json-vs-xml) – Sariq Shaikh Dec 17 '14 at 18:29

1 Answers1

0

Serialization is much more efficient than XML and easier to get working.

Writing out an object in a serialized form is a little faster than text/XML form. Serialized form is much more compact and so saves memory and bandwidth. It's also much faster and easier to parse than XML.

However you want to use XML if you want to edit these files or use them with other program languages (it's just easier to work with).

I would go with serialization .

arc
  • 4,553
  • 5
  • 34
  • 43