top of page

Java Serialization

  • Writer: Ruben van Breda
    Ruben van Breda
  • Nov 24, 2020
  • 1 min read

Serialization is a mechanism of converting the state of an Object into a byte stream. Once rep- resented as a byte stream, the Object can be sent through an output stream, for example to a File. Deserialization is the reverse process where the byte stream is used to recreate the actual Java Object in memory. This mechanism is used to persist the Object, or transmit it across a network. To make a Java Object serializable we implement the java.io.Serializable interface. This interface has no methods, but signifies that the Object is serializable. Note, that for simple examples like the one we will see here, this is sufficient. However, note that serialization is a complex Java topic that has many idiosyncratic aspects. As such, you should use this approach mainly for Java Objects that are not too complex. Complexity in this instance means that they should not have Object instance variables, which have Object instance variables, which have Object instance variables ... In such scenarios, you may need to create customised deserialization methods, and these





ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("cashRegister.obj"))); oos.writeObject(yourObject);


Recent Posts

See All

Comments


CSossa

  • White Facebook Icon
  • White Twitter Icon
  • White Pinterest Icon
  • White Instagram Icon

Thanks for submitting!

bottom of page