0% found this document useful (0 votes)
7 views22 pages

60+ Java String Snippets CCEE MCQ

The document provides a list of various programming projects using Spring Boot, React JS, and MySQL, along with their YouTube links for further exploration. It also includes a series of Java programming quiz questions and answers related to string manipulation and class characteristics. Additionally, it offers subscription options for premium materials and community engagement through a Telegram group.

Uploaded by

Ram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views22 pages

60+ Java String Snippets CCEE MCQ

The document provides a list of various programming projects using Spring Boot, React JS, and MySQL, along with their YouTube links for further exploration. It also includes a series of Java programming quiz questions and answers related to string manipulation and class characteristics. Additionally, it offers subscription options for premium materials and community engagement through a Telegram group.

Uploaded by

Ram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Explore More

Subcription : Premium CDAC NOTES & MATERIAL @99

Contact to Join Click to Join


Premium Group Telegram Group

For More E-Notes


Join Our Community to stay Updated

TAP ON THE ICONS TO JOIN!


Project List

pg. 1 contact us on 8007592194 / 9284926333 www.codewitharrays.in


Project List

pg. 2 contact us on 8007592194 / 9284926333 www.codewitharrays.in


Project List

pg. 3 contact us on 8007592194 / 9284926333 www.codewitharrays.in


Project List

Spring Boot + React JS + MySQL Project List


Sr.No Project Name YouTube Link
1 Online E-Learning Hub Platform Project https://youtu.be/KMjyBaWmgzg?si=YckHuNzs7eC84-IW
2 PG Mate / Room sharing/Flat sharing https://youtu.be/4P9cIHg3wvk?si=4uEsi0962CG6Xodp
3 Tour and Travel System Project Version 1.0 https://youtu.be/-UHOBywHaP8?si=KHHfE_A0uv725f12
4 Marriage Hall Booking https://youtu.be/VXz0kZQi5to?si=llOS-QG3TpAFP5k7
5 Ecommerce Shopping project https://youtu.be/vJ_C6LkhrZ0?si=YhcBylSErvdn7paq
6 Bike Rental System Project https://youtu.be/FIzsAmIBCbk?si=7ujQTJqEgkQ8ju2H
7 Multi-Restaurant management system https://youtu.be/pvV-pM2Jf3s?si=PgvnT-yFc8ktrDxB
8 Hospital management system Project https://youtu.be/IynIouBZvY4?si=CXzQs3BsRkjKhZCw
9 Municipal Corporation system Project https://youtu.be/cVMx9NVyI4I?si=qX0oQt-GT-LR_5jF
10 Tour and Travel System Project version 2.0 https://youtu.be/_4u0mB9mHXE?si=gDiAhKBowi2gNUKZ

Sr.No
Project Name YouTube Link
11 Tour and Travel System Project version 3.0 https://youtu.be/Dm7nOdpasWg?si=P_Lh2gcOFhlyudug
12 Gym Management system Project https://youtu.be/J8_7Zrkg7ag?si=LcxV51ynfUB7OptX
13 Online Driving License system Project https://youtu.be/3yRzsMs8TLE?si=JRI_z4FDx4Gmt7fn
14 Online Flight Booking system Project https://youtu.be/m755rOwdk8U?si=HURvAY2VnizIyJlh
15 Employee management system project https://youtu.be/lD1iE3W_GRw?si=Y_jv1xV_BljhrD0H
16 Online student school or college portal https://youtu.be/4A25aEKfei0?si=RoVgZtxMk9TPdQvD
17 Online movie booking system project https://youtu.be/Lfjv_U74SC4?si=fiDvrhhrjb4KSlSm
18 Online Pizza Delivery system project https://youtu.be/Tp3izreZ458?si=8eWAOzA8SVdNwlyM
19 Online Crime Reporting system Project https://youtu.be/0UlzReSk9tQ?si=6vN0e70TVY1GOwPO
20 Online Children Adoption Project https://youtu.be/3T5HC2HKyT4?si=bntP78niYH802I7N
pg. 4 contact us on 8007592194 / 9284926333 www.codewitharrays.in
1) What is wrong with the below code? Why it is showing compile time error?

1 class MyStringClass extends String


2 {
3 String name;
4 }

View Answer

You can’t extend String class as it is a final class.

2) What will be the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String name = "JavaConceptOfTheDay".substring(4);
6
7 System.out.println(name);
8 }

4
9 }

9
21
View Answer

59
ConceptOfTheDay 07
80

3) What will be the output of the following code?


.in

1 public class JavaStringsQuiz


2 {
ys

3 public static void main(String[] args)


4 {
ra

5 String s = "1".repeat(5);
6
ar

7 System.out.println(s);
8 }
ith

9 }
w
de

View Answer
co

11111

4) What will be the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 System.out.println("1".concat("2").repeat(5).charAt(7));
6 }
7 }

View Answer

5) To which of the following classes, you can create objects without using new operator?
. String
. StringBuffer
. StringBuilder

View Answer

1. String

6) What will be the output of the below program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String string = "string".replace('i', '0');
6
7 System.out.println(string.substring(2, 5));
8 }
9 }

View Answer

r0n

9 4
21
7) In my application, I want mutable and thread safe string objects. Which class do you refer me to use? String or StringBuffer
or StringBuilder?

59
View Answer
07
StringBuffer as it provides mutable and thread safe string objects.
80

8) What will be the output of the following program?


.in

1 public class JavaStringsQuiz


ys

2 {
3 public static void main(String[] args)
ra

4 {
ar

5 System.out.println("Java" == new String("Java"));


6 }
ith

7 }
w

View Answer
de
co

false

9) What will be the outcome of the below program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str = " Java\tConcept\tOf\tThe\tDay ".strip();
6
7 System.out.println(str);
8 }
9 }

View Answer

Java Concept Of The Day

10) What will be the output of the following program?


1 public class JavaStringsQuiz
2 {
3 public static void main(String[] args)
4 {
5 if("string".toUpperCase() == "STRING")
6 {
7 System.out.println(true);
8 }
9 else
10 {
11 System.out.println(false);
12 }
13 }
14 }

View Answer

false

11) String, StringBuffer and StringBuilder – all these three classes are final classes. True or False?
View Answer

9 4
True

21
59
12) What will be the output of the below program?
07
1 public class JavaStringsQuiz
2 {
80

3 public static void main(String[] args)


4 {
5 String str1 = "Java";
.in

6
7 String str2 = "Java";
ys

8
9 System.out.println(str1 == str2);
ra

10
ar

11 System.out.println(str1.equals(str2));
12
ith

13 System.out.println(str1.hashCode() == str2.hashCode());
14 }
w

15 }
de

View Answer
co

true
true
true

13) Guess the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str1 = "Java";
6
7 String str2 = new String("Java");
8
9 System.out.println(str1 == str2);
10
11 System.out.println(str1.equals(str2));
12
13 System.out.println(str1.hashCode() == str2.hashCode());
14 }
15 }
View Answer

false
true
true

14) Guess the output of the following program?

49
21
1 public class JavaStringsQuiz
2 {

59
3 public static void main(String[] args)
4 { 07
5 String str1 = new String("Java");
6
7 String str2 = new String("Java");
80

8
9 System.out.println(str1 == str2);
.in

10
11 System.out.println(str1.equals(str2));
12
ys

13 System.out.println(str1.hashCode() == str2.hashCode());
14 }
ra

15 }
ar
ith

View Answer
w

false
de

true
true
co

15) What will be the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str1 = "Java";
6
7 String str2 = str1.intern();
8
9 System.out.println(str1 == str2);
10
11 System.out.println(str1.equals(str2));
12
13 System.out.println(str1.hashCode() == str2.hashCode());
14 }
15 }

View Answer
true
true
true

16) What will be the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str1 = "Java";
6
7 String str2 = str1.intern();
8
9 String str3 = new String("Java");
10
11 System.out.println(str1 == str2);
12
13 System.out.println(str2 == str3);
14
15 System.out.println(str3 == str1);
16 }
17 }

9 4
21
View Answer

59
true
false
07
false
80

17) What will be the output of the following code?


.in

1 public class JavaStringsQuiz


ys

2 {
3 public static void main(String[] args)
ra

4 {
5 String str1 = "1";
ar

6
7 String str2 = "22";
ith

8
9 String str3 = "333";
w

10
de

11 System.out.println(str1.concat(str2).concat(str3).repeat(3));
12 }
co

13 }

View Answer

122333122333122333

18) hashCode() and equals() methods are overridden in –


. java.lang.String
. java.lang.StringBuffer
. java.lang.StringBuilder
View Answer

1) java.lang.String

19) Guess the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String s1 = "ONE";
6
7 s1.concat("TWO");
8
9 s1.concat("THREE");
10
11 System.out.println(s1);
12 }
13 }

View Answer

ONE

20) What will be the output of the below program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String s1 = "1";
6

4
7 System.out.println(s1.concat("2").concat("3"));

9
8 }

21
9 }

59
View Answer 07
123
80
.in

21) Tinku is developing an application in which string concatenation is very frequent. Which string class do you refer him to
use? And also he doesn’t need code to be thread safe.
ys

View Answer
ra

In such scenarios where string concatenation is very frequent, StringBuffer and StringBuilder classes give better performance than
ar

String class. As StringBuffer is thread safe and StringBuilder is not, StringBuilder will be optimal choice here.
ith
w

22) What will be the output of the following program?


de

1 public class JavaStringsQuiz


2 {
co

3 public static void main(String[] args)


4 {
5 System.out.println("Java"+1000+2000+3000);
6 }
7 }

View Answer

Java100020003000

23) Guess the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 System.out.println(1000+2000+3000+"Java");
6 }
7 }
View Answer

6000Java

24) What will be the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 System.out.println(7.7+3.3+"Java"+3.3+7.7);
6 }
7 }

View Answer

11.0Java3.37.7

25) What will be the output of the following program?

9 4
1 public class JavaStringsQuiz

21
2 {
3 public static void main(String[] args)

59
4 {
5 System.out.println("ONE"+2+3+4+"FIVE");
6 }
07
7 }
80

View Answer
.in

ONE234FIVE
ys
ra

26) What will be the outcome of the following program?


ar

1 public class JavaStringsQuiz


ith

2 {
3 public static void main(String[] args)
w

4 {
de

5 System.out.println("JAVAJ2EE".substring(2, 5).substring(1).charAt(2));
6 }
co

7 }

View Answer

Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 2

27) What will be the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String s1 = new String("JAVA");
6
7 String s2 = new String("JAVA");
8
9 System.out.println(s1 == s2);
10
11 System.out.println(s1.equals(s2));
12
13 System.out.println(s1 == s2.intern());
14
15 System.out.println(s1.intern() == s2.intern());
16
17 System.out.println(s1.intern() == s2);
18 }
19 }

View Answer

false
true
false
true
false

28) What will be the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 System.out.print("0".indent(0));
6 System.out.print("1".indent(1));
7 System.out.print("2".indent(2));

4
8 System.out.print("3".indent(3));

9
9 System.out.print("4".indent(4));

21
10 System.out.print("5".indent(5));
11 }

59
12 }
07
View Answer
80

0
1
.in

2
3
ys

4
5
ra
ar

29) What will be the output of the following program?


ith

1 public class JavaStringsQuiz


w

2 {
de

3 public static void main(String[] args)


4 {
co

5 System.out.println("Java Concept Of The Day".substring(8, 4));


6 }
7 }

View Answer

Exception in thread “main” java.lang.StringIndexOutOfBoundsException: begin 8, end 4, length 23


(beginIndex is greater than endIndex)

30) join() is an instance method in java.lang.String class. True or False?


View Answer

False. join() is a static method in java.lang.String class.

31) What will be the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String[] strings = {"Java", "Python", "JavaScript", "HTML", "CSS"};
6
7 String languages = String.join("_", strings);
8
9 System.out.println(languages);
10 }
11 }

View Answer

Java_Python_JavaScript_HTML_CSS

32) What will be the output of the below program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 System.out.println("A".compareTo("B"));
6 System.out.println("B".compareTo("A"));
7 }
8 }

94
21
View Answer

59
-1
1
07
80

33) What will be the output of the following program?


.in

1 public class JavaStringsQuiz


2 {
ys

3 public static void main(String[] args)


4 {
ra

5 String string = "JAVA";


6
ar

7 StringBuffer sbuffer = new StringBuffer(string);


8
ith

9 StringBuilder sBuilder = new StringBuilder(string);


10
w

11 System.out.println(string.equals(sbuffer));
de

12
13 System.out.println(string.equals(sBuilder));
14
co

15 System.out.println(sbuffer.equals(sBuilder));
16 }
17 }

View Answer

false
false
false

34) Does java.lang.String class has static methods? If yes, what are those?
View Answer

Yes, java.lang.String class has static methods. They are,


1) copyValueOf()
2) format()
3) join()
4) valueOf()
All these methods are overloaded.

35) chars() method is introduced from Java 9 in java.lang.String class. True or False?
View Answer

True

36) What will be the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 "ABC123abc".chars().forEach(System.out::println);
6 }
7 }

View Answer

9 4
65

21
66
67
49

59
50
51
07
97
98
80

99
.in

37) What will be the output of the below program?


ys

1 public class JavaStringsQuiz


ra

2 {
3 public static void main(String[] args)
ar

4 {
5 String s1 = "null"+null+1;
ith

6
7 System.out.println(s1);
w

8 }
de

9 }
co

View Answer

nullnull1

38) Does the following code compiles successfully? If yes, what will be the output?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String s1 = 1+null+"null";
6
7 System.out.println(s1);
8 }
9 }

View Answer

No. Above code shows compile time error. You can use ‘+’ for string and null but not for int and null.
39) Can we use strings in switch case?
View Answer

Yes, from Java 7, strings can be used in switch case.

40) What will be the outcome of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str = "Java Concept Of The Day";
6
7 System.out.println(str.indexOf('a') + str.indexOf("Day"));
8 }
9 }

View Answer

21

9 4
21
41) What will be the output of the following program?

59
1 public class JavaStringsQuiz
2 {
3 public static void main(String[] args)
07
4 {
5 String str = "Java Concept Of The Day";
80

6
7 System.out.println(str.indexOf('a', 5));
8 }
.in

9 }
ys

View Answer
ra
ar

21
ith
w

42) What will be the output of the following code?


de

1 public class JavaStringsQuiz


co

2 {
3 public static void main(String[] args)
4 {
5 String str = "JavaConceptOfTheDay";
6
7 System.out.println(str.charAt(str.length()));
8 }
9 }

View Answer

Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 19

43) What is the default capacity of StringBuffer?


View Answer

16

44) What will be the output of the below code?


1 public class JavaStringsQuiz
2 {
3 public static void main(String[] args)
4 {
5 String str = "Java Concept Of The Day";
6
7 System.out.println(str.replace("a", "A").lastIndexOf('a'));
8 }
9 }

View Answer

-1

45) java.lang.String class has append() method. Right or Wrong?


View Answer

46) Does the following code runs without errors? If yes, what will be the output?

1 public class JavaStringsQuiz

4
2 {

9
3 public static void main(String[] args)

21
4 {
5 StringBuilder sb = new StringBuilder(-32);

59
6
7 sb.append("ABC"); 07
8
9 System.out.println(sb);
10 }
80

11 }
.in

View Answer
ys

Above code throws run time error. Initial capacity of StringBuilder can’t be negative.
ra
ar

47) What will be the outcome of the below program?


ith

1 public class JavaStringsQuiz


w

2 {
de

3 public static void main(String[] args)


4 {
co

5 String str = null;


6
7 System.out.println(str.isBlank());
8 }
9 }

View Answer

Exception in thread “main” java.lang.NullPointerException: Cannot invoke “String.isBlank()” because “str” is null

48) What will be the output of the following code?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str = " ";
6
7 System.out.println(str.isBlank());
8
9 System.out.println(str.isEmpty());
10 }
11 }

View Answer

true
false

49) Does the following code executes successfully? If yes, what will be the output?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 StringBuffer sb = new StringBuffer("01234");
6
7 sb.append(1.1).append('A').append(22).append(false).append("null");
8
9 System.out.println(sb);
10 }
11 }

View Answer

9 4
21
Yes, above code executes successfully. Output will be,
012341.1A22falsenull

59
50) What will be the output of the following program?
07
80
1 public class JavaStringsQuiz
2 {
3 public static void main(String[] args)
.in

4 {
5 StringBuilder sb = new StringBuilder("0123456789");
ys

6
7 System.out.println(sb.delete(3, 6).deleteCharAt(4).deleteCharAt(5));
ra

8 }
9 }
ar
ith

View Answer
w
de

01268
co

51) What will be the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str1 = "123321123";
6
7 System.out.println(str1.replaceFirst("123", "321").replaceAll("12", "21").substring(3, 6));
8 }
9 }

View Answer

321

52) Which of these classes have delete() and reverse() method – java.lang.String, java.lang.StringBuffer and
java.lang.StringBuilder?
View Answer
java.lang.StringBuffer and java.lang.StringBuilder have delete() and reverse() methods.

53) What will be the output of the below code?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 StringBuffer sb = new StringBuffer("11111");
6
7 System.out.println(sb.insert(3, false).insert(5, 3.3).insert(7, "One"));
8 }
9 }

View Answer

111fa3.One3lse11

54) java.lang.String class implements which of the following interfaces?


. Serializable

4
. CharSequence

9
. Comparable

21
. All of the above

59
View Answer
07
4. All of the above
80

55) Guess the output of the following program?


.in

1 public class JavaStringsQuiz


ys

2 {
3 public static void main(String[] args)
ra

4 {
5 String str1 = "Java J2EE Spring Hibenate SQL";
ar

6
7 String str2 = "Python Java Scala C C++";
ith

8
9 System.out.println(str1.contains("HTML") == str2.contains("HTML"));
w

10 }
de

11 }
co

View Answer

true

56) Can you predict the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String str1 = "OnE tWo ThReE fOuR";
6
7 String str2 = "oNeTwOtHrEeFoUr";
8
9 System.out.println(str1.trim().equalsIgnoreCase(str2));
10 }
11 }

View Answer
false

57) Appendable interface is implemented by which of the following classes?


. java.lang.String
. java.lang.StringBuffer
. java.lang.StringBuilder
. java.io.StringWriter
. 2, 3 & 4
View Answer

5) 2, 3 & 4

58) Guess the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 StringBuffer sb = new StringBuffer("One Two Three Four Five");
6

4
7 System.out.println(sb.reverse().indexOf("Two"));

9
8 }

21
9 }

59
View Answer 07
-1
80
.in

59) StringBuffer and StringBuilder classes have intern() method. True or False?
View Answer
ys
ra

False
ar
ith

60) Guess the output of the following program?


w

1 public class JavaStringsQuiz


de

2 {
3 public static void main(String[] args)
co

4 {
5 "Java\nConcept\nOf\nThe\nDay".lines().forEach(System.out::println);
6 }
7 }

View Answer

Java
Concept
Of
The
Day

61) What will be the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 String[] strings = "Java_Concept_Of_The_Day".split("_", 3);
6
7 for (String string : strings)
8 {
9 System.out.println(string);
10 }
11 }
12 }

View Answer

Java
Concept
Of_The_Day

62) What will be the output of the following program?

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 System.out.println(String.valueOf(10)+String.valueOf(1.1)+String.valueOf(true));
6 }
7 }

4
View Answer

9
21
101.1true

59
63) Guess the output of the following program?
07
80
1 public class JavaStringsQuiz
2 {
3 public static void main(String[] args)
.in

4 {
5 System.out.println(String.join(",", "1", "2", "3").concat(",").repeat(3).lastIndexOf(','));
ys

6 }
7 }
ra
ar

View Answer
ith

17
w
de

64) What will be the output of the following program?


co

1 public class JavaStringsQuiz


2 {
3 public static void main(String[] args)
4 {
5 StringBuffer sb1 = new StringBuffer("11111");
6
7 StringBuffer sb2 = sb1.append(22222).reverse();
8
9 System.out.println(sb1 == sb2);
10 }
11 }

View Answer

true
https://www.youtube.com/@codewitharrays

https://www.instagram.com/codewitharrays/

https://t.me/codewitharrays Group Link: https://t.me/ccee2025notes

+91 8007592194 +91 9284926333

codewitharrays@gmail.com

https://codewitharrays.in/project

You might also like