Podcast
Questions and Answers
What is a stream in Java?
What is a stream in Java?
- A type of file that stores data
- A data structure that holds data in memory
- An object that represents data being delivered to or from an object (correct)
- A way of accessing data in parallel
How does a stream deliver data?
How does a stream deliver data?
- One kilobyte at a time
- One byte at a time or one character at a time (correct)
- One megabyte at a time
- One gigabyte at a time
What is a code example of a stream?
What is a code example of a stream?
- Reader and Writer
- BufferedReader and BufferedWriter
- Socket and ServerSocket
- FileInputStream and FileOutputStream (correct)
What are the two kinds of streams in Java?
What are the two kinds of streams in Java?
What do Byte Streams do?
What do Byte Streams do?
What do Character Streams do?
What do Character Streams do?
Why is buffering used in Java?
Why is buffering used in Java?
What is expensive in terms of accessing data?
What is expensive in terms of accessing data?
What is the purpose of the LineNumberReader?
What is the purpose of the LineNumberReader?
What is setLineNumber() used for in LineNumberReader?
What is setLineNumber() used for in LineNumberReader?
What is the purpose of the BufferedReader?
What is the purpose of the BufferedReader?
What is the purpose of the PrintWriter?
What is the purpose of the PrintWriter?
What is the default behavior of PrintWriter?
What is the default behavior of PrintWriter?
What can a PrintWriter wrap?
What can a PrintWriter wrap?
What is the purpose of the File class?
What is the purpose of the File class?
What is the purpose of the InputStreamReader?
What is the purpose of the InputStreamReader?
Study Notes
Streams
- A stream is an object that represents data being delivered to or from an object, one byte or character at a time.
- There are two kinds of streams: Byte Streams and Character Streams (also known as "readers" and "writers").
- Byte Streams read and write raw bytes, while Character Streams read and write characters (16-bit Unicode).
Readers and Writers
- Readers and Writers are Character Streams that read and write characters.
- Examples of Readers and Writers include FileReader, FileWriter, and PrintWriter.
Buffering
- Buffering is used to improve performance when accessing data outside of memory (e.g., disk, network, web).
- It is more efficient to access a large chunk of data at once rather than one byte or character at a time.
LineNumberReader
- A LineNumberReader is a buffered character-input stream that keeps track of line numbers.
- The setLineNumber() method does not seek to a line in the file, but rather designates the line number of the first line.
InputStreamReader and PrintWriter
- InputStreamReader converts bytes from an InputStream to characters, using the proper encoding.
- PrintWriter prints formatted representations of objects to a text-output stream.
- System.out is a PrintWriter.
Using Streams on the Web
- Streams can be used to read from a URL object, URLConnection object, and write to a URLConnection object or HttpServletResponse object.
File
- A File object is a wrapper for a String, and does not necessarily denote something on the file system.
- A File object can be created with any string, regardless of whether it's a valid filename or not.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Learn about Java streams, readers, writers, buffers, and files. Understand the concept of streams, their behavior, and how they are used in Java I/O operations.