476). Which of these classes is used for input and output operation when working with bytes?
[A]InputStream
[B]Reader
[C]Writer
[D] All of the mentioned
Show Answer
Correct Answer: InputStream
Notes:
Answer: a
Explanation: InputStream & OutputStream are designed for byte stream. Reader and writer are designed for character stream.
477). Which of these class is used to read and write bytes in a file?
[A]FileReader
[B]FileWriter
[C]FileInputStream
[D]InputStreamReader
Show Answer
Correct Answer: FileInputStream
Notes:
Answer: c
Explanation: None.
478). Which of these method of InputStream is used to read integer representation of next available byte input?
[A]read()
[B] scanf()
[C]get()
[D]getInteger()
Show Answer
Correct Answer: read()
Notes:
Answer: a
Explanation: None.
479). Which of these data type is returned by every method of OutputStream?
[A]int
[B]float
[C]byte
[D]none of the mentioned
Show Answer
Correct Answer: none of the mentioned
Notes:
Answer: d
Explanation: Every method of OutputStream returns void and throws an IOExeption in case of errors.
480). Which of these is a method to clear all the data present in output buffers?
[A]clear()
[B]flush()
[C]fflush()
[D]close()
Show Answer
Correct Answer: flush()
Notes:
Answer: b
Explanation: None.
481). Which of these method(s) is/are used for writing bytes to an outputstream?
[A]put()
[B]print() and write()
[C]printf()
[D]write() and read()
Show Answer
Correct Answer: print() and write()
Notes:
Answer: b
Explanation: write() and print() are the two methods of OutputStream that are used for printing the byte data.
482). What will be the output of the following Java program? (Note: inputoutput.java is stored in the disk.)
import java.io.*;
class filesinputoutput
{
public static void main(String args[])
{
InputStream obj = new FileInputStream("inputoutput.java");
System.out.print(obj.available());
}
}
[A]true
[B]false
[C] prints number of bytes in file
[D]prints number of characters in the file
Show Answer
Correct Answer: prints number of bytes in file
Notes:
Answer: c
Explanation: obj.available() returns the number of bytes.
Output:$ javac filesinputoutput.java
$ java filesinputoutput
1422(Output will be different in your case)
483). What will be the output of the following Java program?
import java.io.*;
public class filesinputoutput
{
public static void main(String[] args)
{
String obj = "abc";
byte b[] = obj.getBytes();
ByteArrayInputStream obj1 = new ByteArrayInputStream(b);
for (int i = 0; i < 2; ++ i)
{
int c;
while ((c = obj1.read()) != -1)
{
if(i == 0)
{
System.out.print((char)c);
}
}
}
}
}
[A]abc
[B]ABC
[C]ab
[D]AB
Show Answer
Correct Answer: abc
Notes:
Answer: a
Explanation: None.
Output:
$ javac filesinputoutput.java
$ java filesinputoutput
abc
484). What will be the output of the following Java program?
import java.io.*;
public class filesinputoutput
{
public static void main(String[] args)
{
String obj = "abc";
byte b[] = obj.getBytes();
ByteArrayInputStream obj1 = new ByteArrayInputStream(b);
for (int i = 0; i < 2; ++ i)
{
int c;
while ((c = obj1.read()) != -1)
{
if (i == 0)
{
System.out.print(Character.toUpperCase((char)c));
}
}
}
}
}
[A]abc
[B]ABC
[C]ab
[D]AB
Show Answer
Correct Answer: ABC
Notes:
Answer: b
Explanation: None.
Output:
$ javac filesinputoutput.java
$ java filesinputoutput
ABC
485). What will be the output of the following Java program?
import java.io.*;
public class filesinputoutput
{
public static void main(String[] args)
{
String obj = "abc";
byte b[] = obj.getBytes();
ByteArrayInputStream obj1 = new ByteArrayInputStream(b);
for (int i = 0; i < 2; ++ i)
{
int c;
while ((c = obj1.read()) != -1)
{
if (i == 0)
{
System.out.print(Character.toUpperCase((char)c));
obj2.write(1);
}
}
System.out.print(obj2);
}
}
}
[A]AaBaCa
[B]ABCaaa
[C]AaaBaaCaa
[D]AaBaaCaaa
Show Answer
Correct Answer: AaBaaCaaa
Notes:
Answer: d
Explanation: None.
Output:
$ javac filesinputoutput.java
$ java filesinputoutput
AaBaaCaaa