File ip op in java questions

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

 Character streams are used for reading and writing text data, while

byte streams are used for reading and writing binary data
 Console class - It provides methods for reading and writing
character-based console input and output
 Read from byte array - ByteArrayInputStream
 A newLine() method is provided in BufferedWriter which is not in
FileWriter.
 import java.io.*;
class h
{
public static void main(String args[]) throws IOException
{
char c;
BufferedReader obj = new BufferedReader(new
InputStreamReader(System.in));
do
{
c = (char) obj.read();
System.out.print(c);
} while(c!='\'');
}
}
………………………………………………………….abc'def/'egh……………
.. abc'

 Which of these class is used to read characters and strings in Java from
console?
A. BufferedReader


 class output
{
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello");
s1.setCharAt(1,x);
System.out.println(s1);
}
}………..Hxllo

 Which of these class contains the methods print() & println()?


A. System
B. System.out
C. BUfferedOutputStream
D. PrintStream
Answer: Option D

 InputStream obj = new FileInputStream("inputoutput.java");


System.out.print(obj.available());
. prints number of bytes in file

 Which of these methods can be used to output a string in an applet?


B. drawString()

 CharArrayReader(char[] buf)
Creates a CharArrayReader from the specified array of chars.

CharArrayReader(char[] buf, int offset, int length)


Creates a CharArrayReader from the specified array of chars.

 public void getChars(int srcBeginIndex, int srcEndIndex, char[] destination, in


t dstBeginIndex)
Parameters
int srcBeginIndex: The index from where copying of characters is started.

int srcEndIndex: The index which is next to the last character that is getting
copied.

Char[] destination: The char array where characters from the string that
invokes the getChars() method is getting copied.

int dstEndIndex: It shows the position in the destination array from where the
characters from the string will be pushed.

Which of these methods is a part of Abstract Window Toolkit (AWT)


?
A. display()
B. paint()
C. drawString()
D. transient()
Answer: Option B

Which of these operators can be used to get run time information


about an object?
A. getInfo
B. Info
C. instanceof
D. getinfoof
Answer: Option C

What is the Message is displayed in the applet made by the following


Java program?

import java.awt.*;
import java.applet.*;
public class myapplet extends Applet
{
public void paint(Graphics g)
{
g.drawString("A Simple Applet", 20, 20);
}
}
A. A Simple Applet
B. A Simple Applet 20 20
C. Compilation Error
D. Runtime Error
Answer: Option A

What is the length of the application box made by the following Java
program?

import java.awt.*;
import java.applet.*;
public class myapplet extends Applet
{
public void paint(Graphics g)
{
g.drawString("A Simple Applet", 20, 20);
}
}
A. 20
B. 50
C. 100
D. System dependent
Answer: Option A

What is the length of the application box made the following Java
program?

import java.awt.*;
import java.applet.*;
public class myapplet extends Applet
{
Graphic g;
g.drawString("A Simple Applet", 20, 20);
}
A. 20
B. Default value
C. Compilation Error
D. Runtime Error
Answer: Option C
Which of these modifiers can be used for a variable so that it can be
accessed from any thread or parts of a program?
A. transient
B. volatile
C. global
D. No modifier is needed
Answer: Option B
 The ZipOutputStream class is used to create zip files in Java. It allows developers to
compress multiple files and directories into a single zip file for efficient storage or
transmission.
 The ByteArrayOutputStream class is used to store binary data in memory. It provides
a byte array that can be accessed and manipulated.

11. Which class is used to read text from the console in Java?
a) SystemInReader

b) ConsoleReader

c) InputStreamReader

d) Scanner ……….d Scanner

import java.io.*;
class demoFile
{
public static void main(String args[])
{
File f = new File("C:/java/xyz");
System.out.print(f.getName());
}
}
……xyz

import java.io.*;
class demoFile
{
public static void main(String args[])
{
File f = new File("C:/java/xyz");
System.out.print(f.getParent());
System.out.print(" " + f.isFile());
}
}…………………..
C:\java false


Which class can be used to read data line by line using readLine() method?

(a) DataOutputtream
(b) DataInputStream
(c) InputStreamReader
(d) BufferedReader…..d

 What will be the output of the following Java program?

import java.io.*;
class Chararrayinput
{
public static void main(String[] args)
{
String obj = "abcdefgh";
int length = obj.length();
char c[] = new char[length];
obj.getChars(0, length, c, 0);
CharArrayReader input1 = new CharArrayReader(c);
CharArrayReader input2 = new CharArrayReader(c, 1, 4);
int i;
int j;
try
{
while((i = input1.read()) == (j = input2.read()))
{
System.out.print((char)i);
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
A. abc
B. abcd
C. abcde
D. none of the mentioned
Answer: Option D

What is the purpose of a FileInputStream in Java?


a) To read text files

b) To write binary files

c) To read binary files

d) To write text files …..b

5. Which of these classes can return more than one character to be returned to input stream?
a) BufferedReader
b) Bufferedwriter
c) PushbachReader
d) CharArrayReader

Answer: c
Clarification: PushbackReader class allows one or more characters to be returned to the input
stream. This allows looking ahead in input stream and performing action accordingly.

 A stream is a sequence of data.In Java a stream is composed


of?

A) Bytes
B) Bits
C) Both A & B
D) None of the above

 5) Which is used for reading streams of raw bytes such as image


data. For reading streams of characters, consider using FileReader?

A) FileInputStream
B) FileOutputStream
C) Both A & B
D) None of the above

 ANSWER: A) FileInputStream
 6) Which is Commonly used Methods of ByteArrayOutputStream
class?

A) ByteArrayOutputStream()
B) ByteArrayOutputStream(int size)
C) public synchronized void writeTo(OutputStream out) throws
IOException
D) Both A & B

 ANSWER: C) public synchronized void writeTo(OutputStream out)


throws IOException
 12) Which class can be used to read data line by line by readLine()
method?
A) BufferedReader
B) InputStreamReader
C) DataInputStream
D) None of the above
NSWER: A) BufferedReader

13) Which is used to converts the byte-oriented stream into
character-oriented stream?

A) Console
B) Scanner
C) InputStreamReader
D) DataInputStreamANSWER: C) InputStreamReader
 15) Which class breaks the input into tokens using a delimiter which
is whitespace bydefault, It provides many methods to read and
parse various primitive values?

A) Console class
B) Scanner class
C) Both A & B
D) None of the above
View Answer / Hide Answer

 ANSWER: B) Scanner class



 16) Which class automatically flushes the data so there is no need
to call flush() method. Moreover, its methods don't throw
IOException?

A) Console class
B) Scanner Class
C) FileInputStream class
D) PrintStream class
View Answer / Hide Answer

 ANSWER: D) PrintStream class

18) Which class is used to uncompress the file in the deflate compression
format, It provides facility to the other uncompression filters?

A) DeflaterOutputStream class
B) InflaterInputStream class
C) Both A & B
D) None of the above
View Answer / Hide Answer

ANSWER: B) InflaterInputStream class

22) Which method of DataInputStream class reads a line from the file and
returns it as a string ?

A) WriteInt()
B) readLine()
C) readInt()
D) writeDouble()
View Answer / Hide Answer
ANSWER: B) readLine()27) In which field of StreamTokenizer if the token
is a word, this filed contains the word that can be used in programming?

A) String sval
B) double nval
C) int ttype
D) static final int TT_WORD
View Answer / Hide Answer

ANSWER: B) double nval


8) StreamTokenization has following programs they are?

A) Tokenizing text file contents


B) Printing file contents
C) Both A & B
D) None of the above
View Answer / Hide Answer

ANSWER: C) Both A & B

Which of these is used to read a string from the input


stream? readLine()

Which of these class is used to read characters and strings in Java from
console?
BufferedReader
StringReader
BufferedStreamReader
InputStreamReader

 23. Multiple Choice

Which of these is a process of writing the state of an object to a


byte stream?

Serialization
Externalization
File Filtering
All of the mentioned

 24. Multiple Choice

Which of these is an interface for control over serialization and


deserialization?
Serializable
Externalization
FileFilter
ObjectInput

 25. Multiple Choice

Which of these is method of ObjectOutputStream class used to


write the object to output stream as required?
Write()
write()
StreamWrite()
writeObject()

 26. Multiple Choice

Which of these is method of ObjectIntputStream class used to read


the object from input stream as required?
read()
Read()
StreamRead()
readObject()

 27. Multiple Choice

How an object can become serializable?


If a class implements java.io.Serializable class
If a class or any superclass implements java.io.Serializable
interface
Any object is serializable
No object is serializable

 28. Multiple Choice

What is serialization?
Turning object in memory into stream of bytes
Turning stream of bytes into an object in memory
Turning object in memory into stream of bits
Turning stream of bits into an object in memory

 29. Multiple Choice

What is deserialization?
Turning object in memory into stream of bytes
Turning stream of bytes into an object in memory
Turning object in memory into stream of bits
Turning stream of bits into an object in memory

 30. Multiple Choice

What type of members are not serialized?


private
protected
transient
public

You might also like