Java IO Fundamentals Flashcards

1
Q

what does the public static field “in” of java.lang.System class represents and what type is it?

A

Represent standard input and is of type java.io.InputStream

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what does the public static field “out” and “err” of java.lang.System class represents and what type are they?

A

output and error streams. They are of type java.io.PrintStream

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

if you do not provide the intended input data type as expect by the format string, what exception you may get?

A

IllegalFormatConversionException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Whats the difference between Character Stream and Byte Streams?

A
  • Character streams are meant for reading or writing to a character- or text-based IO such as text files, text documents, XML and HTML files while Byte Streams are meant for reading or wiriting to a binary data IO such as executable files, image files, and files in low level file format such as .zip, .class, .exe..
  • Character streams data is dealt with 16-bit unicode class while Byte Streams is dealt with 1 byte (8 bits)
  • For Character stream Input and output character streams are called readers and writers, while input and and output byte streams are called input streams and output streams
  • Character streams uses abstract classes of Reader and Writer, for Byte Streams its classes are called InputStream and OutputStream
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

give a short description of the class StringReader deriving from the reader class

A

character stream that operates on a string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

give a short description of the class InputStreamReader deriving from the reader class

A

bridge between character stream and byte streams

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

give a short description of the class FileReader deriving from the reader class

A

devired class of InputStreamReader that provides support for reading character files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

give a short description of the class BufferedReader deriving from the reader class

A

adds buffering to the underlying character stream so there is no need to access the underlying file system for each read and write operation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

give a short description of the class StringWriter deriving from the Writer class

A

a character stream that collects the output in a string buffer, which can be used for creating a string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

give a short description of the class OutputStreamWriter deriving from the Writer class

A

this class is a bridge between character streams and byte streams

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

give a short description of the class FileWriter deriving from the Writer class

A

derived class of OutputStreamWriter that provides support for writing character files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

give a short description of the class PrintWriter deriving from the Writer class

A

supports formatted printing of characters to the output character stream

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between Streams and Reader/Writers?

A
  • The Stream classes are used for inputting all types of binary/byte data
  • Reader and writers classes are used for inputting and outputting only characters and string data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Does PrintWriter has a PrintReader?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the four abstract classes that are parent of all Stream Classes?

A
  • InputStream
  • OutputStream
  • Reader
  • Writer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the classes that extend from InputStream?

A
  • FileInputStream (low level)
  • FilterInputStream
    • BufferedInputStream (extends FilterInputStream)
  • ObjectInputStream
17
Q

Which are the classes that extend from Reader?

A
  • BufferedReader
  • InputStreamReader
    • File Reader ( extends from InputStreamReader) (low level)
18
Q

Which are the classes that extend from OutputStream?

A
  • FileOutputStream (low level)
  • FilterOutputStream
    • BufferedOutputStream (extend from FilterOutputStream)
    • PrintStream(extend from FilterOutputStream)
  • ObjectOutputStream
19
Q

Which classes classes extend from Writer?

A
  • BufferedWriter
  • OutputStreamWriter
    • FileWriter (low level)
  • PrintWriter
20
Q

What does System.in return?

A

InputStream

21
Q

What does System.out return?

A

PrintStream

22
Q

The console class provides access to which instances?

A

Reader and PrintWriter using the methods reader() and writer() respectively

23
Q

(Console)

What does the readLine() method do?

A

Retrieves a single line of text from the user and the user press enter to terminate it

24
Q

(Console)

What does the readPassword() return?

A

Array of characters

25
True or false Most methods in the File class that interacts with the file system are capable of throwing an exception at runtime
True
26
If we want to move a file using File, what method do we have to use?
renameTo() since there are no move() or mv() methods
27
If we want to create a directory using File class, what method do we have to use?
mkdir() or mkdir(), since there are no createDirectory() method
28
What are the two output methods that the console class has?
format() and printf(), there is no println or out methods
29
What does the method isReady from Reader do?
The ready method just checks if there are more bytes available to read
30
In which case can the Console object be acquired?
when the JVM is started from the interactive command line without redirecting the standard input and output streams