Log In Register

Units


Java String - Questions and Answers

 

Practice these Java String under Java Programming walk-in interview Questions/ examination questions with best tricks and short cuts with solution. Student (candidate) who want to crack the walk in interview, competitive exams and want to find short cuts and tricks to solve questions on Java String for following purpose.


– Anyone who is wishing to increase their perfect knowledge of Java String of Java Programming.
– Anyone who is preparing for aptitude test and increase his in depth aptitude knowledge Java Programming specifically Java String.
– Anyone who is preparing for interviews (competitive examinations, govt examinations and bank examinations, off-campus or on campus interviews, walk-in interview and company interviews) having questions on Java String under Java Programming.

– Anyone who is preparing for aptitude test or competitive exam or entrance exam.
– Anyone who is preparing for entrance examinations and other competitive examinations.
– All Experienced, Freshers and Students.

Here is list of Questions and Answers covering all key area of  Java String topic of Java Programming:

 

1. What could be output of the following fragment of code? public class Test{ public static void main(String args[]){ String x = "hellow"; int y = 9; System.out.println(x += y); } }

Answer: Option B

Explanation:

2. How many Constructor String class have?

Answer: Option

Explanation:

3.

What will be the output of the following program?

public class Test{
        public static void main(String args[]){
		String str1 = "one";
		String str2 = "two";
		System.out.println(str1.concat(str2));
        }
}

Answer: Option C

Explanation:

Concat() method appends one String to the end of another. The method returns a String with the value of the String passed into the method appended to the end of the String which is used to invoke this method.

4. Which of these data type value is returned by equals() method of String class?

Answer: Option C

Explanation:
equals() method of string class returns boolean value true if both the string are equal and false if they are unequal.

5.
String str1 = "Kolkata".replace('k', 'a');

In the above statement, the effect on string Kolkata is 

Answer: Option B

Explanation:

replace() method returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
Syntax: Here is the syntax of this method:
public String replace(char oldChar, char newChar)
Parameters: Here is the detail of the parameters:
oldChar -- the old character. newChar -- the new character.
Return Value: It returns a string derived from this string by replacing every occurrence of oldChar with

6. String in Java is a?

Answer: Option A

Explanation:

7. What will be the output of the following program? public class Test{ public static void main(String args[]){ String str1 = "one"; String str2 = "two"; System.out.println(str1.concat(str2)); } }

Answer: Option C

Explanation:
Concat() method appends one String to the end of another. The method returns a String with the value of the String passed into the method appended to the end of the String which is used to invoke this method.

8.

The output of the following fraction of code is

public class Test{
        public static void main(String args[]){
	        String s1 = new String("Hello");
		String s2 = new String("Hellow");
		System.out.println(s1 = s2);
	}
}

Answer: Option B

Explanation:

9.  Which of these operators can be used to concatenate two or more String objects?

Answer: Option A

Explanation:
operator + is used to concatenate strings, Example String s = “i ” + “like ” + “java”; String s contains “I like java”.

10. Determine output: public class Test{ public static void main(String args[]){ String s1 = 'SITHA' ; String s2 = 'RAMA'; System.out.println(s1.charAt(0) > s2.charAt(0)); } }

Answer: Option

Explanation:

11. How many objects will be created? String a = new String("TestMirror"); String b = new String("TestMirror"); String c = "TestMirror"; String d = "TestMirror";

Answer: Option B

Explanation:
Object will be created each time whenever we use new keyword. So, 2 object will be created simply for the first two line and matter is with remaining two bottom line. String c="TestMirror" creates an object and store it in String pool, next time when we are writing String d="TestMirror" it will first check in String pool whether object already exists or not. Since, it is existing, no new object will be created. Hence reference "d" points to existing object "TestMirror". So ultimately 3 object wi

12.

Determine output:

public class Test{
        public static void main(String args[]){ 	
		String s1 = "SITHA";
		String s2 = "RAMA";
		System.out.println(s1.charAt(0) > s2.charAt(0));
        }
}

Answer: Option A

Explanation:

Output will be True. Since when s1.charAt(0) ascii value is greater then s2.charAt(0). So it will return True.

13. What will be the output? 1. public class Test{ 2. public static void main(String args[]){ 3. Object myObj = new String[]{"one", "two", "three"}; 4. { 5. for(String s : (String[])myObj) 6. System.out.print(s + "."); 7. } 8. } 9. }

Answer: Option A

Explanation:

14. What will be the output of the following program code? class LogicalCompare{ public static void main(String args[]){ String str1 = new String("OKAY"); String str2 = new String(str1); System.out.println(str1 == str2); } }

Answer: Option

Explanation:

15. The class string belongs to ................. package.

Answer: Option B

Explanation: