PRACTICE • LEARN • GROW
Module 8: Strings & Text Processing - Final Quiz MCQs
Solve topic-wise placement questions and improve your skills.
Module 8: Strings & Text Processing - Final Quiz Progress
0 of 11 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
Where is the String Constant Pool (SCP) located in modern Java (Java 7 and later)?
A.
In the PermGen space
B.
Inside the general Heap memory, allowing pooled strings to be garbage collected when unreferenced
C.
In the thread's Stack memory
D.
In the OS virtual page table
Explanation & Key
Correct Answer:
2
Which of the following is NOT one of the primary reasons why String was designed to be immutable in Java?
A.
Security (network connections, database URLs, and file paths cannot be maliciously altered)
B.
Thread safety (immutable objects can be shared freely across threads without synchronization)
C.
String Constant Pool caching (pooling is only safe when strings cannot change)
D.
To force developers to use StringBuilder for every single string operation
Explanation & Key
Correct Answer:
3
Why is performing repeated string concatenation with
+ inside a tight loop considered a critical performance anti-pattern?
A.
Because it throws OutOfMemoryError immediately
B.
Because each '+' creates a new intermediate StringBuilder and new String object in the heap, causing O(N^2) memory allocations and heavy GC pressure
C.
Because the '+' operator is deprecated for strings
D.
Because it reverses the order of characters
Explanation & Key
Correct Answer:
4
What is the key architectural difference between
StringBuilder and StringBuffer?
A.
StringBuilder is synchronized (thread-safe); StringBuffer is not synchronized
B.
StringBuffer is synchronized (thread-safe with method-level locking); StringBuilder is unsynchronized, faster, and preferred for single-threaded usage
C.
StringBuilder is immutable; StringBuffer is mutable
D.
StringBuffer has a maximum size of 256 characters
Explanation & Key
Correct Answer:
5
What will be the output of invoking .intern() in the following snippet?
String s1 = new String("Java");
String s2 = s1.intern();
String s3 = "Java";
System.out.println((s1 == s2) + " " + (s2 == s3));
A.
true true
B.
false true
C.
true false
D.
false false
Explanation & Key
Correct Answer:
6
Which syntax correctly checks the number of characters in a String object named
title?
A.
title.length
B.
title.length()
C.
title.size()
D.
title.count()
Explanation & Key
Correct Answer:
7
What is printed by this code demonstrating String immutability?
String str = "Hello";
str.concat(" World");
System.out.println(str);
A.
Hello World
B.
Hello
C.
World
D.
Compilation error
Explanation & Key
Correct Answer:
8
What will be printed by the following code demonstrating compile-time string constant folding?
String s1 = "Java";
String s2 = "Ja" + "va";
String s3 = new String("Java");
System.out.println((s1 == s2) + " " + (s1 == s3));
A.
true true
B.
true false
C.
false true
D.
false false
Explanation & Key
Correct Answer:
9
What will be printed by inspecting the capacity and length of a newly instantiated StringBuilder?
StringBuilder sb = new StringBuilder();
System.out.println(sb.capacity() + " " + sb.length());
A.
0 0
B.
16 0
C.
16 16
D.
32 0
Explanation & Key
Correct Answer:
10
What is printed by the following substring call?
String text = "Antigravity";
System.out.println(text.substring(0, 4));
A.
Antig
B.
Anti
C.
Ant
D.
IndexOutOfBoundsException
Explanation & Key
Correct Answer:
11
Why did Java 9 replace
char[] with byte[] plus a coder flag (Compact Strings) inside java.lang.String?
A.
To allow strings to store raw binary image files
B.
Because the vast majority of string characters fit in 1 byte (Latin-1), cutting Java heap memory usage for strings by up to 50%
C.
To eliminate the need for Unicode encoding
D.
To speed up disk I/O exclusively
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong