Primitive Types
Which control structure allows a set of statements to be executed repeatedly based on a given boolean condition at the start of each iteration?
switch statement
while loop
for-each loop
if statement
What will happen if an exception is thrown inside a method but it is not caught within that same method?
The compiler automatically generates a catch block to handle it at runtime.
The exception will propagate up the call stack to be handled by a higher-level method or cause the program to terminate.
The program immediately terminates without any attempt to handle the exception elsewhere.
The method re-executes until the exception no longer occurs.
Which of the following sorting algorithms is most efficient for sorting a nearly sorted list of n elements?
Selection sort
Bubble sort
Quick sort
Insertion sort
When should an ArrayList be used over an array in Java?
When memory usage needs to be minimized
When you need fixed-size collections only
When you need to store primitives only
When you need a resizable collection of elements
What could be a consequence of changing .equals()
method call comparison between strings with ==
operator?
Strings with identical content will now yield different hash codes.
It might compare memory addresses instead of actual string content.
String length calculations may become inconsistent post-modification.
The garbage collector may prematurely collect strings being compared.
Which statement about finally blocks in Java is true?
They can only execute if no exceptions were thrown in preceding try blocks.
They must contain return statements for any value-returning methods containing them.
They execute after try or catch blocks, regardless if an exception was thrown or not.
They override any exceptions thrown within associated try and catch blocks, preventing propagation.
When comparing different implementations of searching algorithms on arrays of integers, which scenario would lead to the worst-case performance for a binary search algorithm?
The target value is at the end of the array after several splits.
The target value is at the midpoint of the array.
The target value does not exist in the array.
The target value is at the beginning of the array after several splits.

How are we doing?
Give us your feedback and let us know how we can improve
When managing a collection of elements that supports quick searches, frequent updates, and maintains elements in sorted order, which data structure is most appropriate?
Linked-list allowing easy insertions and deletions however not optimized for quick sorted-order lookups.
Balanced binary search tree such as an AVL tree or Red-black tree which offers logarithmic times for both searching and updating operations while maintaining balanced properties.
Heap data structure ensuring quick access to the extremum elements but lacking efficiency in keeping sorted order after modifications.
Associative array providing fast searches but potentially inefficient updating if resorting is necessary after each update.
What is the best choice when you need to make decisions in your code based on one out of several possible integer or enumerated values?
nested if statements
ternary operator
switch statement
if-else chain
What would likely be the result of replacing if (x > y)
with if (x >= y)
in a method that returns the larger of two integer values?
A compile-time error occurs due to syntax issues.
The program will enter an infinite loop.
The method will always return y regardless of x's value.
The method could return x when x and y are equal.