Java Java Data Structures Efficiency! Custom Serialization

Dhruv Patel
Dhruv Patel
8,287 Points

I want to know why Craig used PrintWriter instead of ObjectOutputStream like before? Does it matter which one you use?

In one of the earlier lessons, Craig used ObjectOutput and InputStream for serializing objects and all i want to know is does it matter which one you use?

1 Answer

Hi Dhruv,

PrintWriter prints formatted representations of objects to a text-output stream.

An ObjectOutputStream writes primitive data types and graphs of Java objects to an OutputStream.

Essentially, PrintWriter is better for printing text, and ObjectOutputStream is better for serialized objects; but whether or not that actually matters for your application is going to depend on what specifically you're using it for.

Dhruv Patel
Dhruv Patel
8,287 Points

Thanks for the response Evan.