Java Input Output - IO Streams Interview Questions Answers - 2

Question: 6

What is the difference between Reader/Writer and InputStream/Output Stream?

The Reader/Writer class is character oriented and the InputStream/OutputStream class is byte oriented.

Question: 7

What one should take care of while serializable the object?

One should make sure that all the included objects are also serializable.

If any objects is not serializable then it throws a NotSerializableException.

Question: 8

What is Stream Unique Identifier (SUID) that is written out as part of the serial stream?

The serialization process uses a unique identification value to keep track of the persisted objects.

When a Serializable or Externalizable object is saved, its fully qualified class name and the Stream Unique Identifier (SUID) of the class is written out of the stream.

The SUID is a unique 64 bit hash and is obtained by applying the SHA – 1 message digest algorithm to the serialized class, including its name, field types and method signatures.

This steps is important as its prevents the data persisted by one class from being read by another class with the same name.

For any class to be able to read successfully from an object stream, it is imperative that its SUID matches the SUID of the serialized data in the stream.

Question: 9

Does serialization depend on the browser, platform, or VM?

The serialization format is independent of browser, independent of JVM vendor and independent of platform.

So serialization should work with any combination of the above.

Question: 10

What is the difference between the file and random access file classes?

The File class encapsulates the files and directories of the local file system.

The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file.

Related Questions