Array Traversal Question
Which method is most commonly used to iterate through each element in an array, performing an operation on each?
- Reverse engineering
- Enhanced for loop
- Binary indexing
- Recursive descent
- Covariant arrays
List Insertion Scenario
In a linked list, what must be updated when inserting a new node in the middle of the list?
- Only the new node's value
- The size of arraylist.
- The autoboxing value of object
- The 'next' pointers of the preceding and new nodes
- Autocasting Generics
Generic List Deletion
What is the most important aspect to consider when deleting an element from a linked list to avoid memory leaks or broken lists?
- Autoboxing the type of the object
- Autocasting a string array
- Updating the 'lastAccessed' variable
- Updating references to 'Minima'
- Autoboxing requires to handle null
Array Search Algorithm
Which of the following search algorithms is NOT typically suitable for unsorted arrays?
- Linear Search
- For Each loop
- Sentinel Search
- Generics casting
- Binary Search
Autoboxing Impact on Performance
How does excessive autoboxing of primitive types affect performance in Java collections?
- Speeds up array creation
- Autoboxing has no effect
- Reduces memory allocation
- Increase run-time performance
- It can lead to increased memory usage and overhead
Generics in Collections
What primary benefit do generics provide when working with collections in Java?
- Solely for auto-casting
- Solely for covariance in arrays
- Discover type-mismatch errors at compile time instead of run time.
- Return arrays from methods which return an Iterable
- Breaks backward compatibility
Covariant Arrays Defect
Why are covariant arrays considered a defect in Java's type system by many programmers?
- Introduce new keywords and break backward compatibility
- Do not incur unnecessary run-time performance overhead
- Circumvent the problem that Java didn't originally include generics in its design
- Lead to ArrayStoreException
- Provide an easy way to create new array of a parameterized type
Arrays Iterable
Why can you not pass an array to a method that expects an Iterable in Java?
- Arrays are covariant
- Arrays are Iterable
- Arrays are iterable by design
- Strings are iterable
- Arrays are not Iterable
Autoboxing True False
Consider the following code: Integer b1 = 120; Integer b2 = 120; System.out.println(b1 == b2); Integer b3 = 200; Integer b4 = 200; System.out.println(b3 == b4); Why does the first group of statements print true, but the second false?
- Because b1 and b2 are references to different Integer objects.
- Java's implementation of valueOf() retrieves a cached values if the integer is between -128 and 127.
- It results in a run-time error.
- Primitive type can store every value of their corresponding wrapper type except null.
- Because arrays are covariant.
Autoboxing Code Fragment
How does autoboxing handle the following code fragment?
- It results in a run-time error.
- Primitive type can store every value of their corresponding wrapper type except null.
- ArrayStoreException
- Strings are iterable
- By redeclaring first