INPUT / OUTPUT : EXPLORING JAVA.IO Questions with answers
Event Handling interview questions and answer in php asp .net , java, c# or c sharp for freshers and experienced with eventhandler
advertisements
INPUT OUTPUT Stream : EXPLORING JAVA.IO Questions with answers are given below
Question :
What is meant by Stream and what are the types of Streams and classes of
the Streams? Answers : A Stream is an abstraction that either produces or consumes
information.
There are two types of Streams. They are:
Byte Streams : Byte Streams provide a convenient means for handling input
and output of bytes.
Character Streams : Character Streams provide a convenient means for
handling input and output of characters.
Byte Stream classes : Byte Streams are defined by using two abstract classes.
They are:InputStream and OutputStream.
Character Stream classes : Character Streams are defined by using two
abstract classes. They are : Reader and Writer. Question : Which of the following statements are true?
UTF characters are all 8-bits.
UTF characters are all 16-bits.
UTF characters are all 24-bits.
Unicode characters are all 16-bits.
Bytecode characters are all 16-bits. Answers : d. Question : Which of the following statements are true?
When you construct an instance of File, if you do not use the filenaming
semantics of the local machine, the constructor will throw an IOException.
When you construct an instance of File, if the corresponding file does not
exist on the local file system, one will be created.
When an instance of File is garbage collected, the corresponding file on
the local file system is deleted.
None of the above. Answers : a,b and c. Question : The File class contains a method that changes the current working
directory.
True
False Answers : b. Question : It is possible to use the File class to list the contents of the current working
directory.
True
False Answers : a. Question : Readers have methods that can read and return floats and doubles.
True
False Answers : b. Question : You execute the code below in an empty directory. What is the result?
File f1 = new File("dirname");
File f2 = new File(f1, "filename");
A new directory called dirname is created in the current working directory.
Question : A new directory called dirname is created in the current working directory.
A new file called filename is created in directory dirname.
A new directory called dirname and a new file called filename are created,
both in the current working directory.
A new file called filename is created in the current working directory.
No directory is created, and no file is created. Answers : e. Question : What is the difference between the Reader/Writer class hierarchy and the
InputStream/OutputStream class hierarchy? Answers : The Reader/Writer class hierarchy is character-oriented and the
InputStream/OutputStream class hierarchy is byte-oriented.
What is an I/O filter? Answers : An I/O filter is an object that reads from one stream and writes to
another, usually altering the data in some way as it is passed from one
stream to another. Question : What is the purpose of the File class? Answers : The File class is used to create objects that provide access to the
files and directories of a local file system. Question : What interface must an object implement before it can be written to a
stream as an object? Answers : An object must implement the Serializable or Externalizable interface
before it can be written to a stream as an object. Question : What is the difference between the File and RandomAccessFile classes? Answers : The File class encapsulates the files and directories of the local
file system. The RandomAccessFile class provides the methods needed to
directly access data contained in any part of a file. Question : What class allows you to read objects directly from a stream? Answers : The ObjectInputStream class supports the reading of objects from
input streams. Question : What value does read( ) return when it has reached the end of a file? Answers : The read( ) method returns – 1 when it has reached the end of a file. Question : What value does readLine( ) return when it has reached the end of a file? Answers : The readLine( ) method returns null when it has reached the end of a
file. Question : How many bits are used to represent Unicode, ASCII, UTF-16 and UTF-8
characters? Answers : Unicode requires 16-bits and ASCII requires 8-bits. Although the
ASCII character set uses only 1-bits, it is usually represented as 8-bits.
UTF-8 represents characters using 8, 16 and 18-bit patterns. UTF-16 uses 16-bit
and larger bit patterns. Question : Which of the following are true?
The InputStream and OutputStream classes are byte-oriented.
The ObjectInputStream and ObjectOutputStream do not support serialized
object input and output.
The Reader and Writer classes are character-oriented.
The Reader and Writer classes are the preferred solution to serialized
object output. Answers : a and c. Question : Which of the following are true about I/O filters?
Filters are supported on input, but not on output.
Filters are supported by the InputStream/OutputStream class hierarchy, but
not by the Reader/Writer class hierarchy.
Filters read from one stream and write to another.
A filter may alter data that is read from one stream and written to
another. Answers : c and d. Question : Which of the following are true?
Any Unicode character is represented using 16-bits.
7-bits are needed to represent any ASCII character.
UTF-8 characters are represented using only 8-bits.
UTF-16 characters are represented using only 16-bits. Answers : a and b. Question : Which of the following are true?
The Serializable interface is used to identify objects that may be written
to an output stream.
The Externalizable interface is implemented by classes that control the way
in which their objects are serialized.
The Serializable interface extends the Externalizable interface.
The Externalizable interface extends the Serializable interface. Answers : a, b and d. Question : Which of the following are true about the File class?
A File object can be used to change the current working directory.
A File object can be used to access the files in the current directory.
When a File object is created, a corresponding directory or file is created
in the local file system.
File objects are used to access files and directories on the local file
system.
File objects can be garbage collected.
When a File object is garbage collected, the corresponding file or
directory is deleted. Answers : b, d and e. Question : How do you create a Reader object from an InputStream object?
Use the static createReader( ) method of InputStream class.
Use the static createReader( ) method of Reader class.
Create an InputStreamReader object, passing the InputStream object as an
argument to the InputStreamReader constructor.
Create an OutputStreamReader object, passing the InputStream object as an
argument to the OutputStreamReader constructor. Answers : c. Question : Which of the following are true?
Writer classes can be used to write characters to output streams using
different character encodings.
Writer classes can be used to write Unicode characters to output streams.
Writer classes have methods that support the writing of the values of any
Java primitive type to output streams.
Writer classes have methods that support the writing of objects to output
streams. Answers : a and b. Question : The isFile( ) method returns a boolean value depending on whether the file
object is a file or a directory.
True.
False. Answers : a. Question : Readingor writing can be done even
after closing the input/output source.
True.
False. Answers : b.
Question : The ________ method helps in clearing the buffer. Answers : flush( ).
The System.err method is used to print error message.
True.
False. Answers : a. Question : What is meant by StreamTokenizer? Answers : StreamTokenizer breaks up InputStream into tokens that are delimited
by sets of characters.
It has the constructor : StreamTokenizer(Reader inStream).
Here inStream must be some form of Reader.
What is Serialization and deserialization? Answers : Serialization is the process of writing the state of an object to a
byte stream.
Deserialization is the process of restoring these objects.
30) Which of the following can you perform using the File class?
a) Change the current directory
b) Return the name of the parent directory
c) Delete a file
d) Find if a file contains text or binary information Answers : b and c. Question : 31)How can you change the current working directory using an instance of
the File class called FileName?
FileName.chdir("DirName").
FileName.cd("DirName").
FileName.cwd("DirName").
The File class does not support directly changing the current directory. Answers : d.
Ask your interview questions on Input output
We have urgent requirement for fresher and 1 year exp candidate.For apply send your resume at career@pcds.co.in