Showing 31–40 of 50 questions
Which of the following is a characteristic of a good hash function?
A
Deterministic behavior
B
Uniform distribution
C
Collision resistance
D
All of the above
Correct Answer:
D. All of the above
Explanation:
Good hash functions are deterministic (same input gives same output), uniformly distribute values, and minimize collisions.
In the context of REST APIs, what does POST primarily do?
A
Retrieve data
B
Create new resources
C
Update existing resources
D
Delete resources
Correct Answer:
B. Create new resources
Explanation:
POST method is used to create new resources on the server. GET retrieves, PUT/PATCH updates, DELETE removes.
What is the main advantage of using microservices architecture?
A
Easier to develop and test
B
Better scalability and flexibility
C
Reduced operational complexity
D
All of the above
Correct Answer:
B. Better scalability and flexibility
Explanation:
Microservices allow independent scaling, deployment, and technology choices. However, they can increase operational complexity.
Which design pattern is used when you want to ensure a class has only one instance?
A
Factory Pattern
B
Singleton Pattern
C
Builder Pattern
D
Observer Pattern
Correct Answer:
B. Singleton Pattern
Explanation:
Singleton Pattern restricts a class to have only one instance and provides a global access point to it.
What will be the output?
List list = new ArrayList();
list.add(1);
list.add(2);
list.add(3);
list.remove(1);
System.out.println(list);
A
[1, 3]
B
[1, 2, 3]
C
[2, 3]
D
[1, 2]
Correct Answer:
A. [1, 3]
Explanation:
list.remove(1) removes the element at index 1 (which is 2), leaving [1, 3].
What is the difference between ArrayList and LinkedList in Java?
A
ArrayList is faster for random access
B
LinkedList is faster for insertions/deletions in middle
C
Both are correct
D
No difference
Correct Answer:
C. Both are correct
Explanation:
ArrayList has O(1) random access but O(n) insertion/deletion. LinkedList has O(n) access but O(1) insertion/deletion.
Which of the following is NOT a principle of object-oriented programming?
A
Inheritance
B
Encapsulation
C
Polymorphism
D
Materialization
Correct Answer:
D. Materialization
Explanation:
The four OOP principles are Inheritance, Encapsulation, Polymorphism, and Abstraction. 'Materialization' is not an OOP principle.
What is the purpose of the 'try-catch' block in Java?
A
To improve code performance
B
To handle exceptions gracefully
C
To declare variables
D
To create loops
Correct Answer:
B. To handle exceptions gracefully
Explanation:
try-catch blocks allow you to handle exceptions without crashing the program, providing graceful error handling.
If a HashMap has 1000 entries and the load factor is 0.75, at what capacity will it resize?
A
750
B
1000
C
1333
D
Cannot be determined
Explanation:
Resize occurs when entries exceed capacity × load factor. If 1000 entries at 0.75 load factor, capacity = 1000/0.75 = 1333
What is the time complexity of accessing an element in a balanced Binary Search Tree?
A
O(1)
B
O(log n)
C
O(n)
D
O(n²)
Correct Answer:
B. O(log n)
Explanation:
In a balanced BST, the height is log n, so searching takes O(log n) time.