Explain how to convert any Java Object into byte array
1. Create an object of ByteArrayOutputStream class.
ByteArrayOutputStream bStream = new ByteArrayOutputStream();
2. Create an object of ObjectOutputStream object and send the reference of ByteArrayOutPutStream object as parameter of ObjectOutputStream constructor.
ObjectOutputStream oStream = new ObjectOutputStream( bStream );
3. Place any object in the method writeObject() of ObjectOutputStream
oStream.writeObject ( obj );
4. Invoke toByteArray() method of ByteArrayOutputStream reference
byte[] byteVal = bStream. toByteArray();