Java String and IO

Java String and IO

30 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

In System.out.println(), the keyword out is the _________.

  1. class
  2. object
  3. method
  4. vriable
Question 2 Multiple Choice (Single Answer)

Which of the following symbols is used for representing the XOR operator in Java?

  1. ~
  2. &
  3. |
  4. ^
Question 3 Multiple Choice (Single Answer)

How many string objects are created by the given statement?
String str=new String(“Aliens”);

  1. 0
  2. 1
  3. 2
  4. 4
Question 4 Multiple Choice (Single Answer)

What will be the value of “str” after executing the following statements?
StringBuffer str=new StringBuffer(“I am a student”);
str.delete(2,6);

  1. I student
  2. Istudent
  3. Itudent
  4. I am a student
Question 5 Multiple Choice (Single Answer)

Which of the following statements is/are correct?
A. The size of a vector can grow or shrink.
B. The size of an array can grow or shrink.

  1. Only A
  2. Only B
  3. Both A and B
  4. Neither A nor B
Question 6 Multiple Choice (Single Answer)

What is the size and capacity of the Vector Num in the following code?
Vector Num=new Vector(10)

  1. Size = 10, capacity = 0
  2. Size = 0, capacity = 10
  3. Size = 10, capacity = 10
  4. Size = 0, capacity = 0
Question 7 Multiple Choice (Single Answer)

Which of the following methods is used to convert a given string to a new character array?

  1. toArray()
  2. StringToArray()
  3. toCharArray()
  4. toCArray()
Question 8 Multiple Choice (Single Answer)

Which of the following methods is used to check whether the stream is ready to read or not?

  1. start()
  2. ready()
  3. isready()
  4. isstart()
Question 9 Multiple Choice (Single Answer)

What would be the value of i after the execution of the following statements in Java?
int i;
String st1=”Rakesh”;
String st2=”Roshan”;
i=st1.compareTo(st2);

  1. 0
  2. 1
  3. -1
  4. +1
Question 10 Multiple Choice (Single Answer)

Which of the following is the correct way to read a character?


  1. ||
    |---|
    | char ch;
    BufferedReader br=new BufferedReader(new InputStreamReader(System.out));
    ch=(char)br.read();|

  2. ||
    |---|
    | char ch;
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    ch=br.read();|

  3. ||
    |---|
    | char ch;
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    ch=(char)br.read();|

  4. ||
    |---|
    | char ch;
    BufferedReader br=new BufferedReader(System.in);
    ch=(char)br.read();|
Question 11 Multiple Choice (Single Answer)

What would be the value of i and ch after the execution of the following statements in Java?
int i;
char ch;
String st1=”Rakesh Roshan”;
i=st1.indexOf(‘e’);
ch=st1.charAt(5);

  1. The value of i will be 4 and the value of ch will be ’s’.
  2. The value of i will be 3 and the value of ch will be ’h’.
  3. The value of i will be 3 and the value of ch will be ’s’.
  4. The value of i will be 4 and the value of ch will be ’h’.
Question 12 Multiple Choice (Single Answer)

The method readLine() can be accessed by the object of a ____________ class to read a string from console.

  1. InputStreamReader
  2. InputStream
  3. BufferedReader
  4. StringReader
Question 13 Multiple Choice (Single Answer)

What is the correct syntax of replace() method of the StringBuffer class?

  1. StringBuffer replace(int s,int e)
  2. StringBuffer replace(int s,String str)
  3. StringBuffer replace(int s,String str1,String str2)
  4. StringBuffer replace(int s,int e,String str)
Question 14 Multiple Choice (Single Answer)

The methods of NumberFormat class are used to display the numbers in standard formats(Currency values and percentage values).The NumberFormat class belongs to which of the following packages?

  1. java.lang
  2. java.io
  3. java.text
  4. java.txt
Question 15 Multiple Choice (Single Answer)

Which of the following statement(s) is/are correct?
A. valueOf() is a static method.
B. toString() is overridden in Integer and Double Class.

  1. Only A
  2. Only B
  3. Both A and B
  4. Neither A nor B
Question 16 Multiple Choice (Single Answer)

How many parameterized constructors are defined for a Scanner class?

  1. 5
  2. 6
  3. 7
  4. 8
Question 17 Multiple Choice (Single Answer)

The constructor StringBuffer() of a StringBuffer class creates a string buffer with the capacity of ________ characters by default.

  1. 8
  2. 16
  3. 32
  4. 64
Question 18 Multiple Choice (Single Answer)

The class String is defined in the package ___________.

  1. java.awt
  2. java.lang
  3. java.math
  4. java.net
Question 19 Multiple Choice (Single Answer)

Java does not support ____________.

  1. arrays
  2. multithreading
  3. pointers
  4. constructors
Question 20 Multiple Choice (Single Answer)

Which of the following methods of a String class is used to compare the given string “str1” to another string “str2” by ignoring the case consideration?

  1. str1.equals(str2);
  2. str1.equalsIgnoreCase(str2)
  3. str1.equalignoreCase(str2)
  4. str1.equalsIgnorecase(str2)
Question 21 Multiple Choice (Single Answer)

Which of the following methods is used to get the index within the given string “str” at the first occurrence of the specified substring “str1”?

  1. str1.indexOf(int ch,int from Index)
  2. str1.indexOf(String str)
  3. str.indexOf(string str1)
  4. str.indexOf(String str1)
Question 22 Multiple Choice (Single Answer)

Which of the following is not a valid statement in Java?

  1. str1.equalsIgnoreCase(str2)
  2. str1.equalsIgnoreCase()
  3. “Hello”.equalsIgnoreCase(“hello”)
  4. str1.equals(str2)
Question 23 Multiple Choice (Single Answer)

Which of the following is the correct printf() statement in Java?

  1. printf(“Hello”);
  2. Printf“Hello”;
  3. System.out.printf(“Hello”);
  4. None of the above
Question 24 Multiple Choice (Single Answer)

Objects of ___________ class are useful in breaking down the inputs from the user into tokens.

  1. InputStreamReader
  2. BufferedReader
  3. Scanner
  4. Tokens
Question 25 Multiple Choice (Single Answer)

Which of the following is the method of a StringTokenizer class?

  1. Token()
  2. nextToken()
  3. println()
  4. ttype()
Question 26 Multiple Choice (Single Answer)

Which of the following is not directly derived from the Reader class?

  1. BufferedReader
  2. InputStreamReader
  3. FilterReader
  4. PushBackReader
Question 27 Multiple Choice (Single Answer)

Character Oriented Input Stream provides support for reading and writing _____ characters.

  1. 1-bit
  2. 8-bit
  3. 16-bit
  4. 32-bit
Question 28 Multiple Choice (Single Answer)

The LineNumberInputStream, DataInputStream, BufferedInputStream, and PushBackInputStream classes are derived from ___________________ class.

  1. FileInputStream
  2. PipedInputStream
  3. FilterInputStream
  4. ByteArrayInputStream
Question 29 Multiple Choice (Single Answer)

In Java, the inputs are always considered as ________ datatypes.

  1. integer
  2. character
  3. byte
  4. string
Question 30 Multiple Choice (Single Answer)

Which of the following methods is used to calculate the number of times the tokenizer's nextToken method can be called before it generates an exception?

  1. numberOfTokens()
  2. countTokens()
  3. numberOfElement()
  4. tokens()