
Q121
Q121 Spot the mistake:
try {
String s = null;
System.out.println(s.length());
}
catch (NullPointerException e) {
System.out.println("Null Error");
}
No error
Null Error should not be caught
s should be initialized
The length() method cannot be used on strings
Q122
Q122 What is the primary advantage of using generics in Java?
Faster execution
Reduced memory usage
Stronger type checking at compile-time
Easier code maintenance
Q123
Q123 What is the difference between a HashMap and a Hashtable in Java?
HashMap is synchronized, Hashtable is not
Hashtable is synchronized, HashMap is not
HashMap allows one null key, Hashtable does not
All of the above
Q124
Q124 In Java Collections Framework, which interface represents a mapping from unique keys to values?
List
Set
Map
Queue
Q125
Q125 What happens when a duplicate key is put into a HashMap?
It replaces the existing key’s value
It is ignored
It throws an exception
A new entry is created
Q126
Q126 What is the difference between the add() and put() methods in Java's Collection Framework?
add() is for lists, put() is for maps
add() inserts at a specific index, put() does not
add() is for sets, put() is for lists
There is no difference
Q127
Q127 Which of the following is true about a TreeMap in Java?
It does not maintain an order
It is not based on the Map interface
It orders elements based on natural ordering or a comparator
It allows null keys
Q128
Q128 What does this Java code output?
Map<Integer, String> map = new HashMap<>();
map.put(1, "Java");
map.put(2, "Python");
System.out.println(map.size());
1
2
3
None
Q129
Q129 What will this Java code print?
Set
set.add(1); set.add(1);
System.out.println(set.size());
1
2
0
Error
Q130
Q130 What is the result of executing this code?
Map<String, Integer> map = new TreeMap<>();
map.put("Python", 3);
map.put("Java", 1);
System.out.println(map);
{Java=1, Python=3}
{Python=3, Java=1}
{1=Java, 3=Python}
Error
Q131
Q131 Determine the output of this pseudocode:
CREATE list = ["Java", "Python", "Java"] FOR EACH element IN list PRINT element
Java Python Java
Java Python
Java
Python Java
Q132
Q132 Analyze this pseudocode:
CREATE set ADD "Java" TO set ADD "Python" TO set ADD "Java" TO set IF "Java" IN set PRINT "Yes" ELSE PRINT "No"
Yes
No
Error
None
Q133
Q133 Identify the issue in this code snippet:
List
The list is empty
The get method is used incorrectly
The list should be a LinkedList
No error
Q134
Q134 Find the error in this Java code:
Map<String, Integer> map = new HashMap<>();
map.put(null, 1);
map.put(null, 2);
System.out.println(map.get(null));
HashMap does not allow null keys
Prints 1
No error
Syntax error
Q135
Q135 Identify the flaw in this Java code:
List
The remove index is out of bounds
LinkedList does not allow insertion at an index
No error
Syntax error
Q136
Q136 How does StringBuilder differ from StringBuffer in Java?
StringBuilder is immutable, StringBuffer is not
StringBuilder is faster as it is not synchronized
StringBuilder and StringBuffer have different methods
There is no difference
Q137
Q137 Why is it recommended to use StringBuilder or StringBuffer for string manipulation in loops?
To reduce memory usage
To increase execution speed
To avoid creating many intermediate String objects
Both B and C
Q138
Q138 In Java, what happens when two string literals with the same content are created?
They refer to different objects in memory
They refer to the same object in the String Constant Pool
A runtime error occurs
A new object is created each time
Q139
Q139 What will this Java code output?
String s1 = "Java";
String s2 = "Java";
System.out.println(s1 == s2);
true
false
An error occurs
None of the above
Q140
Q140 What does this Java code do?
StringBuilder sb = new StringBuilder("Java");
sb.append(" Programming");
System.out.println(sb);
Appends " Programming" to sb and prints "Java Programming"
Creates a new StringBuilder object
Throws an error
Prints "Java"
Q141
Q141 What is the main difference between a single-threaded and a multi-threaded application?
Single-threaded applications can perform multiple tasks at once
Multi-threaded applications are always faster
Single-threaded applications use less memory
Multi-threaded applications can perform multiple tasks at the same time
Q142
Q142 In Java, what is the difference between a user thread and a daemon thread?
User threads are low priority, daemon threads are high priority
User threads run in the background, daemon threads do not
User threads prevent the JVM from exiting, daemon threads do not
Daemon threads are used for garbage collection
Q143
Q143 What is the primary purpose of the wait() and notify() methods in Java?
To start and stop threads
To manage thread priorities
To handle synchronization between threads
To handle exceptions in threads
Q144
Q144 Analyze the output of this code snippet:
class MyThread extends Thread { public void run() {
for(int i = 0;
i < 5;
i++) {
System.out.println(i); }
}
} public class Main {
public static void main(String[] args) {
MyThread t = new MyThread();
t.start();
for(int i = 5;
i < 10;
i++) {
System.out.println(i); }
}
}
The numbers 0 to 9 in sequential order
The numbers 5 to 9 followed by 0 to 4
A mix of numbers 0 to 9 in no particular order
A runtime error
Q145
Q145 Spot the mistake:
synchronized void myMethod() { notify(); wait(); }
wait() should be called before notify()
notify() and wait() cannot be in the same method
No error
The method is not properly synchronized
Q146
Q146 How does the Date and Time API in Java 8 improve over the older java.util.Date class?
It provides more methods for date manipulation
It is thread-safe and immutable
It supports internationalization better
All of the above
Q147
Q147 What is the purpose of the CompletableFuture class in Java?
To simplify multithreading programming
To replace the use of raw threads
To provide a more complex future interface
To handle synchronous programming
Q148
Q148 In Java, what are the benefits of using Callable and Future interfaces?
To handle synchronization between threads
To perform operations in the background and retrieve their results
To handle exceptions in multithreaded code
To manage thread lifecycle
Q149
Q149 Analyze the output of this code snippet:
List
asList(1, 2, 3);
numbers.stream().
map(n -> n * n).
forEach(System.out::println);
Prints the squares of the numbers
Prints the numbers multiplied by 2
Prints the sum of the numbers
Prints the numbers as they are
Q150
Q150 What is a key consideration when designing an application to support multiple languages?
Ensuring all text is in English and translated later
Using non-localized date and time formats
Using external files for text to facilitate easy translation
Hardcoding all strings in the application

