9

As we all know Serialization in java is a mechanism of writing the state of an object into a byte stream.

It is mainly used to send object's state across the network. But what happens when object is not serialized and is sent across the network .

Will it give errors?

Thank you

user207421
  • 305,947
  • 44
  • 307
  • 483
Kapil Devmurari
  • 159
  • 3
  • 11
  • 9
    *But what happen when object is not serialized and travel object's state on the network* **How**? – Elliott Frisch Apr 19 '16 at 13:17
  • 1
    http://stackoverflow.com/questions/447898/what-is-object-serialization – AdamSkywalker Apr 19 '16 at 13:17
  • 3
    It is unclear what you're asking here. You don't always require serialization/deserialization. If you're sending an object over a network, then it gets serialized to send it via a byte stream. That's the point of serialization, precisely so that you CAN send via a network. – ManoDestra Apr 19 '16 at 13:19
  • When you say 'serialized' do you by any chance mean `Serializable`? NB There is no [tag:nio] aspect to this question. Don't tag indiscriminately. – user207421 Apr 25 '16 at 00:46

1 Answers1

13

We use Object Serialization for mainly two reasons:
1. Communication over the network
2. Lightweight persistence–the archival of an object

Before I respond to what errors you will get, let me take a dig at

Why do we need Serialization?

The main drivers for this are our network infrastructure and the hardware disks that understands bits and bytes but not JAVA objects. Serialization helps to translate graph of Java objects into an array of bytes for storage or transmission. All this happens due to the ObjectInputStream/ObjectOutputStream classes, full-fidelity metadata, and the willingness of programmers to "opt in" to this process by tagging their classes with the Serializable marker interface.

What happens if you try to send non-serialized Object over network?

When traversing a graph, an object may be encountered that does not support the Serializable interface. In this case the NotSerializableException will be thrown and will identify the class of the non-serializable object.

The Roy
  • 2,178
  • 1
  • 17
  • 33