Core Java - Interview Questions and Answers

341. 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) A new directory called dirname is created in the current working directory.
b) A new directory called dirname is created in the current working directory. A new file called filename is created in directory dirname.
c) A new directory called dirname and a new file called filename are created, both in the current working directory.
d) A new file called filename is created in the current working directory.
No directory is created, and no file is created.

Ans : e.

342. What is the difference between the Reader/Writer class hierarchy and the
InputStream/OutputStream class hierarchy?

Ans : The Reader/Writer class hierarchy is character-oriented and the InputStream/OutputStream class hierarchy is byte-oriented.

343. What is an I/O filter?

Ans : 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.

344. What is the purpose of the File class?

Ans : The File class is used to create objects that provide access to the files and directories of a local file system.

345. What interface must an object implement before it can be written to a stream as an object?

Ans : An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.

346. What is the difference between the File and RandomAccessFile classes?

Ans : 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.

347. What class allows you to read objects directly from a stream?

Ans : The ObjectInputStream class supports the reading of objects from input streams.

348. What value does read( ) return when it has reached the end of a file?

Ans : The read( ) method returns – 1 when it has reached the end of a file.

349. What value does readLine( ) return when it has reached the end of a file?

Ans : The readLine( ) method returns null when it has reached the end of a file.

350. How many bits are used to represent Unicode, ASCII, UTF-16 and UTF-8 characters?

Ans : 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.

Post a Comment

Mới hơn Cũ hơn