Header Ads

Java White Box Testing---String Handling--Must Know-10

String handling is a very important part of java.While Testing people should know how it is working...

Which package does define String and StringBuffer classes?
Ans : java.lang package.
Which method can be used to obtain the length of the String?
Ans : length( ) method.
How do you concatenate Strings?
Ans : By using " + " operator.
Which method can be used to compare two strings for equality?
Ans : equals( ) method.
Which method can be used to perform a comparison between strings that ignores case differences?
Ans : equalsIgnoreCase( ) method.
What is the use of valueOf( ) method?
Ans : valueOf( ) method converts data from its internal format into a human-readable form.
What are the uses of toLowerCase( ) and toUpperCase( ) methods?
Ans : The method toLowerCase( ) converts all the characters in a string from uppercase to
The method toUpperCase( ) converts all the characters in a string from lowercase to
Which method can be used to find out the total allocated capacity of a StrinBuffer?
Ans : capacity( ) method.
Which method can be used to set the length of the buffer within a StringBuffer object?
Ans : setLength( ).
What is the difference between String and StringBuffer?
Ans : String objects are constants, whereas StringBuffer objects are not.
String class supports constant strings, whereas StringBuffer class supports growable, modifiable strings.
What are wrapper classes?
Ans : Wrapper classes are classes that allow primitive types to be accessed as objects.
Which of the following is not a wrapper class?
Ans : a.
What is the output of the following program?
public class Question {
public static void main(String args[]) {
String s1 = "abc";
String s2 = "def";
String s3 = s1.concat(s2.toUpperCase( ) );
None of the above
ANS : c.
Which of the following methods are methods of the String class?
delete( )
append( )
reverse( )
replace( )
Ans : d.
Which of the following methods cause the String object referenced by s to be changed?
s.concat( )
s.toUpperCase( )
s.replace( )
s.valueOf( )
Ans : a and b.
String is a wrapper class?
Ans : b.
17) If you run the code below, what gets printed out?
String s=new String("Bicycle");

int iBegin=1;

char iEnd=3;

c) icy
d) error: no method matching substring(int,char)
Ans : b.
18) Given the following declarations
String s1=new String("Hello")

String s2=new String("there");

String s3=new String();
Which of the following are legal operations?
s3=s1 + s2;
s3=s1 - s2;
c) s3=s1 & s2
d) s3=s1 && s2
Ans : a.
19) Which of the following statements are true?
The String class is implemented as a char array, elements are addressed using the stringname[] convention
b) Strings are a primitive type in Java that overloads the + operator for concatenation
c) Strings are a primitive type in Java and the StringBuffer is used as the matching wrapper type
d) The size of a string can be retrieved using the length property.
Ans : b.
Powered by Blogger.