Explain how to convert any Java Object into byte array? - Java

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();

Explain how to convert bytes[] into File object - Java
1. Create a File object. File file = new File(“path and file name here”);...
JavaSpaces technology vs. database - Java
Java spaces is a technology with powerful high-level tool for the development of distributed and collaborative applications. A simple API is provided based on the network shared space for developing sophisticated distributed applications...
Methods for accessing system properties about the Java virtual machine
The system properties are accessed by the method System.getProperties(). This method returns a Properties object...
Post your comment