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 Organizing Data Serialization

CLARIFYING SOME CONCEPTS

Hey, I really think it would help if some expert clarify here some concepts:

0) Why would I want to "serialize" data? Examples please!

1) Why is he creating an array of size "0" and later he is able to change it?

2) What is a stream (not a vague explanation please, the long one...)

3) Why do we need TWO streams?

4) How does he know that this methods tends to cause THESE exceptions?

Thank you and keep the cool work treehouse!

I'm not expert, just like you I'm learning this tutorial. Here is what I understand:

0) Serialize is essentially use the computer program to save object in a file. 1) 0 size means it is empty, i guess. 2) A stream can be defined as a sequence of data. there are two kinds of Streams. InPutStream: The InputStream is used to read data from a source. OutPutStream: the OutputStream is used for writing data to a destination. 3)One is input file and one is output file. 4)those exception are standard or rules to follow in case of errors.

2 Answers

I'll do my best to help you, im also a student trying to figure out what in the world i've just learn.

0) Why would I want to "serialize" data? Examples please! Craig said in the video this is the most basic type of serialization, and that more complex or useful versions of this concept will hit us right in the face in the future of our programming journey, in general I assume it's like a 'save' button inside your code.

1) Why is he creating an array of size "0" and later he is able to change it? he's doing it while using the word 'new' which means that a new array is formed inside the memory and pointed to the array's name, later on he writes: (NOTE: ive named my array tArr instead, dont know why) tArr=(Treet[])ois.readObject() , here he is casting what ois.readObject() returns(which i guess is an object or an array of objects(?)) to a treet array. 2) What is a stream (not a vague explanation please, the long one...) An I/O Stream represents an input source or an output destination. A stream can represent many different kinds of sources and destinations, including disk files, devices, other programs, and memory arrays. Streams support many different kinds of data, including simple bytes, primitive data types, localized characters, and objects. Some streams simply pass on data; others manipulate and transform the data in useful ways. No matter how they work internally, all streams present the same simple model to programs that use them: A stream is a sequence of data. A program uses an input stream to read data from a source, one item at a time A program uses an output stream to write data to a destination, one item at time. This is the definition from docs.oracle, the company who founded Java's documentation of stuff.

3) Why do we need TWO streams? Input Stream and Output stream The first one is to read data and LOAD it to the program (console in our case) the second one is to write date and SAVE it to the database(like, server or wherever you like to save stuff)

4) How does he know that this methods tends to cause THESE exceptions? I guess its common exceptions, mainly because we're talking about I/O so an IOException is bound to happen if someone screws with your future program, the ClassNotFound exception is in the case,well, if there is no class.

Hope I've managed to clear things up and help a bit, im as dumb as I can be regarding some of the content on these courses. Good luck!!

shu Chan
shu Chan
2,951 Points

These are good questions, and Linda had some great answers but I was wondering if anyone else could chime in. Should we as students just not get distracted by all this right now? Or are we expected to be competent with this in this portion of the course?