Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.