























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An in-depth analysis of java input and output streams, focusing on fileoutputstream, bufferedinputstream, datainputstream, and objectinputstream. Topics covered include constructing 'stacks' of streams, writing to and reading from files, and the advantages and disadvantages of arrays. Additionally, the document discusses the java collections framework and its use with lists.
Typology: Assignments
1 / 63
This page cannot be seen from the preview
Don't miss anything!
Data Structures #
Estimated Grade Ranges
Each question was
graded on a 5-point
scale. The total possible
was 65.
Lecture 14, p. 8
(^) Streams provide random access to the bytes in a
(^) fi le.
fi^ Streams provide a common means for accessing data in les, network hosts, and other devices.
(^) Input streams will supply data endlessly or until closed.
e^ Accessing stream data in small chunks is often more cient than in large chunks.
(^) Streams deal primarily with signed bytes.
Which type of stream do these statements relate to?3. Input Stream (I), Output Stream (O), or both (B)?
Lecture 14
(^) write(int)
(^) method.
(^) -
(^) to indicate end-of-stream.
(^) IOException
.
5a. What method(s) must be called on an
(^) InputStream
when you are
(^) fi nished with it? Why?
close()
(^) must be called to return limited resources to the
attempts to instantiateoperating system. Not closing streams can cause further
(^) FileInputStream
s to fail.
OutputStream 5b. What method(s) must be called on an
(^) when you are
(^) fi nished with it? Why?
flush()
(^) must be called followed by
close()
(^) to ensure
that all output data is forced to the device.
Lecture 14, pg. 23
(^) is
(^) is a valid,
initialized
(^) InputStream
). The
(^) InputStream
for (int i = 0; i < buffer.length; i++) byte[] buffer = new byte[256]; contains a long sequence of zero byte values:
buffer[i] = i;
The value of int b = is.read(buffer);
(^) b = 16
, what then is the value of
(^) buffer[16]
?
Lecture 14, pg. 15
0 1 2 3 4 5 6 7 8
9 10 11 12 13 14 15 16 17
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 16 17
Value Index
Changed by
(^) read()
(^) method
Changed by
(^) for
(^) loop
(^) ObjectOutputStream
(^) (O) or manual serialization
apply to?(M)? To which type of serialization do these statements
Lecture 17, p. 4
(^) You can design the binary format.
so^ Automatically adds information about the objects’ classes,
(^) fi les tend to be a little larger.
(^) Can be used to exchange objects with non-Java programs.
(^) Requires you to write less code.
Lecture 17, pg. 36
BufferedInputStream
DataInputStream
FileInputStream
ByteArrayInputStream
(^) •
ObjectInputStream
Which range of indices of the byte[] fields = new byte[2000];FileOutputStream("Electron.dat"); OutputStream os = new 11. If you have the following code:
(^) fields
(^) array will the
following line of code write to the
(^) fi le?
os.write(fields, 500, 1000);
Lecture 14, pg. 23
500
through
1499
(^) java.io.IOException
(^) a checked or an
whether through the use of a It’s a checked exception, which requires explicit handling, for programming I/O?unchecked exception? What are the consequences of this
(^) throws
(^) clause on I/O
exceptions), or containment within amethods (to delegate responsibility for handling potential
(^) try
/ catch
/ finally
block (to respond to potential exceptions).
Lecture 14, pg. 18
makes it efData structures are things that store objects in a way that
fi cient to look them up later.
right one depends on the application.There are several different ways to look up objects and the
Sometimes you want objects sorted by one of theirSometimes you want to store objects in a certain order.Sometimes you want to look up objects by a "code" or token.
(^) fi elds.
Sometimes you want objects grouped into categories.
lists, sets (sorted and unsorted), and maps. The collections we will deal with primarily come in three kinds:collections to manage objects in various ways.The Java Collections Framework provide a number of different
Arrays have the following advantages:The simplest form of data structure is an array.
Very low overhead: it is the most ef
fi cient data structure in
out of order.Random access: there is no penalty for accessing elementsterms of memory use.
Arrays have the following disadvantages:
Size is
(^) fi xed at creation time. You must either allocate the
one.go through every element in sequence, looking for the right Searching for a particular object is slow because you have tomiddle of the array.You can't insert elements into or delete elements from theof the unique index values you wish to use to hold the object.Arrays don't help you organize data. You pick and keep trackelements to a new, larger array as needed.largest array you will ever need, or manually copy the
8
12
0
2
-
98 -
int[] a
[0] [1] [2] [3] [4] [5] [6] 8
12
0
2
-
98 -
int[] b
[0] [1] [2] [3] [4] [5] [6]
8
12
0
2
-
98 -
int[] a
[0] [1] [2] [3] [4] [5] [6] 8
12
0
2
-
98 -
int[] b
[0] [1] [2] [3] [4] [5] [6]
7
b[3] = 7;