Generate 100 multiple choice questions on a particular topic. Difficulty scales…
- User
Generate 100 multiple choice questions on a particular topic. Difficulty scales available are basic, intermediate, advanced and expert. Generate questions for Expert level difficulty. Generate questions in JSON format in single line, no other text should be outputted. JSON model: [{n:question number,q:"question",c:["choice"],a:"answer"}] Topic: Java Loops
- Assistant
[
{n:1,q:"What will be the output of the following Java code snippet?\n\nint x = 0;\nfor(int i = 0; i < 5; i++) {\n x = x++;\n}\nSystem.out.println(x);",c:["0","4","5","Compilation error"],a:"0"},
{n:2,q:"In Java, which of the following loop constructs allows modification of the loop variable within the loop body without affecting the iteration count?",c:["Enhanced for-loop","Traditional for-loop","While loop","Do-while loop"],a:"Enhanced for-loop"},
{n:3,q:"Considering Java's Just-In-Time (JIT) compiler optimizations, which loop optimization technique is NOT automatically performed?",c:["Loop unrolling","Loop inversion","Loop fusion","Loop interchange"],a:"Loop interchange"},
{n:4,q:"What is the primary reason to use a labeled break statement in nested loops in Java?",c:["To exit all loops immediately","To continue to the next iteration of the outer loop","To break out of a specific outer loop","To improve performance"],a:"To break out of a specific outer loop"},
{n:5,q:"Given the following code, what will be the output?\n\nfor(int i = 0; i < 5; i++) {\n for(int j = 0; j < 5; j++) {\n if(i * j > 6) {\n break;\n }\n System.out.print(i * j + " ");\n }\n}",c:["0 0 0 0 0 0 1 2 3 4 0 2 4 ","0 0 0 0 0 0 1 2 3 4 ","Compilation error","0 0 0 0 0 0 1 2 3 "],a:"0 0 0 0 0 0 1 2 3 "},
{n:6,q:"Which of the following statements about the Java for-each loop is FALSE?",c:["It can be used with arrays.","It can be used with instances of Iterable.","The loop variable can be modified to affect the underlying collection.","It does not provide access to the index of the current element."],a:"The loop variable can be modified to affect the underlying collection."},
{n:7,q:"In Java, what will happen if you attempt to use a for-each loop on a custom class that implements Iterable but does not properly implement the iterator() method?",c:["Runtime exception","Compilation error","Silent failure","The loop will execute zero times"],a:"Runtime exception"},
{n:8,q:"How does the Java compiler handle an empty loop body in terms of performance optimization?",c:["Removes the loop completely","Leaves the loop as is","Optimizes the loop to reduce overhead","Throws a warning"],a:"Optimizes the loop to reduce overhead"},
{n:9,q:"What is the potential problem with modifying a collection while iterating over it using a for-each loop?",c:["ConcurrentModificationException","ArrayIndexOutOfBoundsException","The modifications are ignored","Compilation error"],a:"ConcurrentModificationException"},
{n:10,q:"Considering Java's loop optimizations, which of the following can lead to more efficient bytecode in loops?",c:["Using postfix operators instead of prefix","Using constants for loop boundaries","Avoiding method calls inside loop conditions","All of the above"],a:"All of the above"},
{n:11,q:"What is the result of the following Java code?\n\nList list = Arrays.asList(1, 2, 3);\nfor(int i = 0; i < list.size(); i++) {\n list.remove(i);\n}\nSystem.out.println(list);",c:["[2, 3]","[1, 3]","[2]","ConcurrentModificationException"],a:"[2]"},
{n:12,q:"In Java, how can an infinite loop impact the JVM's garbage collector?",c:["It can prevent garbage collection from occurring","It has no impact","It slows down garbage collection","It causes an OutOfMemoryError"],a:"It can prevent garbage collection from occurring"},
{n:13,q:"Which of the following best describes loop inversion as an optimization technique in Java?",c:["Converting a while loop to a do-while loop","Rewriting a loop to minimize the number of iterations","Replacing a for loop with recursion","Transforming a loop to use conditional logic before entering the loop body"],a:"Transforming a loop to use conditional logic before entering the loop body"},
{n:14,q:"What is the main advantage of using the Streams API over traditional loops in Java 8 and above?",c:["Improved readability and declarative style","Better performance in all cases","Simpler exception handling","Less memory usage"],a:"Improved readability and declarative style"},
{n:15,q:"In Java, what is loop fusion, and how does it affect performance?",c:["Combining adjacent loops that iterate over the same range","Splitting a loop into multiple loops","Rewriting loops to use fewer variables","It has no effect on performance"],a:"Combining adjacent loops that iterate over the same range"},
{n:16,q:"What will be the output of the following Java code?\n\nint[] arr = {1, 2, 3};\nfor(int i : arr) {\n arr[i - 1] = arr[i - 1] * 2;\n}\nSystem.out.println(Arrays.toString(arr));",c:["[2, 4, 6]","[2, 2, 2]","[2, 4, 3]","[2, 4, 0]"],a:"[2, 4, 6]"},
{n:17,q:"Which of the following is true about the relationship between loop unrolling and method inlining in Java?",c:["They are unrelated optimizations","Loop unrolling can enable method inlining","Method inlining can enable loop unrolling","Both optimizations are mutually exclusive"],a:"Method inlining can enable loop unrolling"},
{n:18,q:"What is the key difference between a 'for' loop and a 'for-each' loop regarding the possibility of index manipulation inside the loop?",c:["'For' loop allows index manipulation; 'for-each' loop does not","'For-each' loop allows index manipulation; 'for' loop does not","Both allow index manipulation","Neither allow index manipulation"],a:"'For' loop allows index manipulation; 'for-each' loop does not"},
{n:19,q:"How does Java handle loop variables in the enhanced for-loop with respect to the collection being iterated?",c:["It creates a copy of the collection","It uses an iterator internally","It relies on array indexing","It doesn't handle collections"],a:"It uses an iterator internally"},
{n:20,q:"In multithreaded Java applications, which of the following loop constructs is thread-safe by default when modifying shared variables?",c:["Synchronized blocks within loops","Volatile variables in loops","Atomic variables in loops","None of the above"],a:"None of the above"},
{n:21,q:"What will be the output of the following Java code?\n\nint sum = 0;\nouter:\nfor(int i = 0; i < 5; i++) {\n for(int j = 0; j < 5; j++) {\n if(i + j > 6) {\n break outer;\n }\n sum += i + j;\n }\n}\nSystem.out.println(sum);",c:["21","28","15","10"],a:"21"},
{n:22,q:"Which Java language feature allows for lazy evaluation within loops, potentially improving performance for large datasets?",c:["Streams API","Enhanced for-loop","Generics","Lambda expressions"],a:"Streams API"},
{n:23,q:"In Java, what is the effect of calling System.exit(0) inside a loop?",c:["Terminates the loop","Throws an exception","Terminates the JVM","No effect"],a:"Terminates the JVM"},
{n:24,q:"Regarding the Java Memory Model, which statement is true about variable visibility in loops across threads?",c:["Variables are always visible to all threads","Volatile variables ensure visibility","Synchronization has no effect","Local variables are shared among threads"],a:"Volatile variables ensure visibility"},
{n:25,q:"What will be the output of the following Java code?\n\nList list = new ArrayList<>(Arrays.asList(1,2,3,4));\nfor(Integer i : list) {\n if(i % 2 == 0) {\n list.remove(i);\n }\n}\nSystem.out.println(list);",c:["[1, 3]","[1, 2, 3, 4]","ConcurrentModificationException","[2, 4]"],a:"ConcurrentModificationException"},
{n:26,q:"Which of the following loop constructs in Java is most suitable for parallelizing operations on large collections?",c:["Parallel streams","Traditional for-loop","Enhanced for-loop","Iterator-based loops"],a:"Parallel streams"},
{n:27,q:"In Java, which loop optimization might the Just-In-Time compiler perform to eliminate unnecessary bounds checking?",c:["Loop unrolling","Range check elimination","Loop fusion","Loop inversion"],a:"Range check elimination"},
{n:28,q:"Why is it generally safer to use 'Iterator.remove()' rather than 'Collection.remove()' inside a loop iterating over a collection?",c:["Prevents ConcurrentModificationException","Improves performance","Simplifies code","No practical difference"],a:"Prevents ConcurrentModificationException"},
{n:29,q:"What will be the output of the following Java code?\n\nint count = 0;\nfor(int i = 0; i < 3; i++) {\n for(int j = 0; j < 3; j++) {\n if(j == i) {\n continue;\n }\n count++;\n }\n}\nSystem.out.println(count);",c:["6","9","3","5"],a:"6"},
{n:30,q:"In Java, which of the following best describes the behavior of a loop that decreases an unsigned integer variable beyond zero?",c:["Results in an underflow exception","Variable wraps around to maximum value","Variable remains at zero","Compilation error"],a:"Compilation error"},
{n:31,q:"How can using 'break' and 'continue' statements within deeply nested loops affect the readability and maintainability of Java code?",c:["Improves readability","Has no effect","Reduces readability","Forces compiler optimizations"],a:"Reduces readability"},
{n:32,q:"What is the potential issue with the following Java loop when used in production code?\n\nfor(;;) {\n // do something\n}",c:["Infinite loop consuming CPU resources","Compilation error","Optimized away by the compiler","Throws an exception"],a:"Infinite loop consuming CPU resources"},
{n:33,q:"Which of the following statements about the 'do-while' loop in Java is true?",c:["The loop body is executed at least once","The condition is evaluated before the loop body","It is functionally equivalent to a 'while' loop","It cannot be nested within other loops"],a:"The loop body is executed at least once"},
{n:34,q:"In Java, what will be the result of attempting to modify a final loop variable inside the loop?",c:["Compilation error","Runtime error","Modification allowed","Variable becomes non-final"],a:"Compilation error"},
{n:35,q:"Which looping construct would you use in Java if the number of iterations is not known beforehand and depends on a certain condition being met during runtime?",c:["While loop","For loop","Do-while loop","Enhanced for-loop"],a:"While loop"},
{n:36,q:"What is the primary benefit of minimizing the scope of loop variables in Java?",c:["Reduces memory usage","Improves performance","Enhances code readability and maintainability","Enables compiler optimizations"],a:"Enhances code readability and maintainability"},
{n:37,q:"How does Java handle exceptions thrown inside the body of a loop?",c:["Exits the loop and propagates the exception","Continues to the next iteration","Handles the exception silently","Restarts the loop"],a:"Exits the loop and propagates the exception"},
{n:38,q:"In Java, what will happen if you attempt to replace a 'for' loop with a 'parallelStream()' operation without considering thread safety?",c:["Improved performance with no issues","Possible concurrency issues and data races","Compilation error","No effect"],a:"Possible concurrency issues and data races"},
{n:39,q:"Which of the following best describes tail-recursion and its relation to loops in Java?",c:["Java optimizes tail-recursive methods into loops","Tail-recursion is more efficient than loops in Java","Java does not optimize tail-recursive methods","Tail-recursion eliminates the need for loops"],a:"Java does not optimize tail-recursive methods"},
{n:40,q:"Considering the Java Memory Model, which statement is true about variables declared inside loops?",c:["They are re-initialized in each iteration","They retain their value between iterations","They cause memory leaks","They are shared between threads"],a:"They are re-initialized in each iteration"},
{n:41,q:"What will be the output of the following Java code?\n\nint i = 0;\nwhile(++i < 5) {\n System.out.print(i);\n}",c:["1234","01234","135","Compilation error"],a:"1234"},
{n:42,q:"In Java, which of the following techniques can help avoid off-by-one errors in loops?",c:["Using zero-based indexing consistently","Starting loop counters at 1","Using floating-point counters","Avoiding the use of 'break' statements"],a:"Using zero-based indexing consistently"},
{n:43,q:"How does the use of iterators in Java's enhanced for-loop help prevent certain types of bugs?",c:["By ensuring thread safety","By preventing index out of bounds errors","By improving performance","By allowing modification of the collection"],a:"By preventing index out of bounds errors"},
{n:44,q:"Which of the following is a characteristic of an infinite loop in Java?",c:["Consumes minimal resources","Always caused by a bug","Can be terminated by a 'break' statement","Automatically optimized by the JVM"],a:"Can be terminated by a 'break' statement"},
{n:45,q:"What is the main disadvantage of using recursion instead of loops in Java in terms of performance?",c:["Recursion is faster but uses more memory","Recursion can lead to stack overflow errors","Recursion is not supported in Java","Recursion makes code less readable"],a:"Recursion can lead to stack overflow errors"},
{n:46,q:"In Java, which of the following can cause a loop to become non-deterministic in its execution time?",c:["Fixed iteration count","Use of random number generation inside the loop","Loop unrolling","Use of 'break' statements"],a:"Use of random number generation inside the loop"},
{n:47,q:"What effect does autoboxing have inside loops in Java, and how can it impact performance?",c:["Improves performance due to caching","Increases memory usage and decreases performance","No effect on performance","Causes compilation errors"],a:"Increases memory usage and decreases performance"},
{n:48,q:"Which of the following scenarios is most likely to benefit from loop unrolling in Java?",c:["Small loops with a known number of iterations","Loops with complex conditions","Large loops with variable iteration counts","Loops that contain I/O operations"],a:"Small loops with a known number of iterations"},
{n:49,q:"In Java, how does the compiler treat unreachable code following a 'break' or 'continue' statement inside a loop?",c:["Ignores it with no warnings","Throws a compilation error","Generates a runtime exception","Optimizes it during execution"],a:"Throws a compilation error"},
{n:50,q:"What will be the output of the following Java code?\n\nint x = 0;\nfor(int i = 0; i < 3; i++) {\n x += i;\n i = 5;\n}\nSystem.out.println(x);",c:["0","1","3","Compilation error"],a:"0"},
{n:51,q:"Which of the following best describes the concept of 'Loop Carried Dependency' in Java loops?",c:["Each iteration depends on the results of the previous one","Iterations are independent","Loop variables are immutable","It refers to recursive loops"],a:"Each iteration depends on the results of the previous one"},
{n:52,q:"In Java, what mechanism allows you to create loops that can iterate over multiple data sources in parallel?",c:["Zip streams","Parallel for-loops","Nested loops","Iterator chaining"],a:"Zip streams"},
{n:53,q:"How does the use of 'Thread.sleep()' inside a loop affect the execution of a Java program?",c:["Pauses the thread without affecting other threads","Halts the entire program","Improves performance","Throws an InterruptedException"],a:"Pauses the thread without affecting other threads"},
{n:54,q:"What is one of the risks associated with using recursive loops in Java without proper termination conditions?",c:["Improved performance","Stack overflow errors","Memory leaks","Deadlocks"],a:"Stack overflow errors"},
{n:55,q:"In Java, what is the impact of loop invariant code motion on performance?",c:["Decreases performance by adding overhead","Has no impact on performance","Improves performance by moving calculations outside the loop","Results in compilation errors"],a:"Improves performance by moving calculations outside the loop"},
{n:56,q:"Which of the following is a valid reason to prefer a 'while' loop over a 'for' loop in Java?",c:["When the number of iterations is fixed","When you need to execute the loop body at least once","When the termination condition is complex","When using multiple loop variables"],a:"When the termination condition is complex"},
{n:57,q:"What will be the output of the following Java code?\n\nint[] nums = {1, 2, 3, 4, 5};\nfor(int i = 0; i < nums.length; i++) {\n nums[i] = nums[++i];\n}\nSystem.out.println(Arrays.toString(nums));",c:["[2, 2, 4, 4, 5]","[2, 3, 4, 5, 5]","ArrayIndexOutOfBoundsException","[2, 3, 4, 5, 0]"],a:"ArrayIndexOutOfBoundsException"},
{n:58,q:"In Java, how can the introduction of side effects within a loop's conditional expression affect the loop?",c:["Makes the loop run faster","Can lead to unexpected behavior","Has no effect","Causes a compilation error"],a:"Can lead to unexpected behavior"},
{n:59,q:"How does loop peeling help in optimizing Java loops?",c:["By unrolling the loop completely","By executing one or more iterations separately","By combining multiple loops into one","By eliminating the loop entirely"],a:"By executing one or more iterations separately"},
{n:60,q:"What is the difference between 'break' and 'return' statements inside a loop in Java?",c:["'Break' exits the loop; 'return' exits the method","Both exit the loop","Both exit the method","'Return' exits the loop; 'break' continues to next iteration"],a:"'Break' exits the loop; 'return' exits the method"},
{n:61,q:"Which of the following best describes a busy-wait loop in Java?",c:["A loop that waits for a condition to become true without relinquishing control","A loop that performs intensive calculations","A loop that waits for user input","A loop that is optimized away by the compiler"],a:"A loop that waits for a condition to become true without relinquishing control"},
{n:62,q:"In Java, what effect does setting the JVM flag '-XX:+LoopUnswitching' have on loop optimizations?",c:["Enables moving loop-invariant conditions outside the loop","Disables all loop optimizations","Forces loops to be unrolled","Has no effect on modern JVMs"],a:"Enables moving loop-invariant conditions outside the loop"},
{n:63,q:"What will be the output of the following Java code?\n\nint i = 0;\nfor(; i < 5; ) {\n System.out.print(i);\n i++;\n}",c:["01234","1234","Compilation error","Infinite loop"],a:"01234"},
{n:64,q:"In Java, what is the purpose of the 'Iterable' interface in relation to loops?",c:["To allow objects to be the target of the 'for-each' loop","To enable parallel processing","To improve performance","To enforce thread safety"],a:"To allow objects to be the target of the 'for-each' loop"},
{n:65,q:"How can using immutable objects within loops in Java enhance thread safety?",c:["By preventing modifications to shared data","By improving performance","By reducing memory usage","It does not enhance thread safety"],a:"By preventing modifications to shared data"},
{n:66,q:"In Java, what is the effect of declaring a loop control variable inside the loop declaration?",c:["Limits the variable's scope to the loop","Causes a compilation error","Makes the variable global","Has no effect on scope"],a:"Limits the variable's scope to the loop"},
{n:67,q:"Which of the following is true about nested loops in Java regarding time complexity?",c:["Nested loops always result in O(n^2) time complexity","Time complexity depends on the specific loop conditions","Nested loops are more efficient","Nested loops have the same complexity as single loops"],a:"Time complexity depends on the specific loop conditions"},
{n:68,q:"What will be the output of the following Java code?\n\nfor(int i = 0; i < 5; i++) {\n switch(i) {\n case 2:\n continue;\n default:\n System.out.print(i);\n }\n}",c:["01234","0134","014","Compilation error"],a:"0134"},
{n:69,q:"In Java, how does the 'Stream.iterate()' method enable the creation of infinite streams, and what's a common way to limit them?",c:["By generating elements on demand; using 'limit()' to cap the size","By storing all elements in memory; using 'skip()' to start later","By precomputing values; using 'filter()' to select elements","It cannot create infinite streams"],a:"By generating elements on demand; using 'limit()' to cap the size"},
{n:70,q:"Which of the following is a potential drawback of deep nesting in loops in Java?",c:["Improved performance","Easier to read and maintain","Increased cognitive load and potential for errors","Compiler optimizations are more effective"],a:"Increased cognitive load and potential for errors"},
{n:71,q:"How does the Java compiler handle constant expressions in loop conditions?",c:["Evaluates them once before the loop starts","Re-evaluates them every iteration","Ignores them","Throws a warning"],a:"Evaluates them once before the loop starts"},
{n:72,q:"What is the main purpose of the 'Iterable' and 'Iterator' interfaces in relation to Java loops?",c:["To support asynchronous operations","To facilitate custom traversal of collections","To optimize performance","To enforce security constraints"],a:"To facilitate custom traversal of collections"},
{n:73,q:"In Java, which of the following is a valid way to prevent a loop from becoming infinite due to floating-point precision errors?",c:["Avoid using '==' for floating-point comparisons","Use integer counters instead","Increase the loop increment step","Rely on compiler optimizations"],a:"Avoid using '==' for floating-point comparisons"},
{n:74,q:"What will be the output of the following Java code?\n\nint[] arr = new int[0];\nfor(int i : arr) {\n System.out.print(i);\n}\nSystem.out.println("Done");",c:["Done","0Done","Compilation error","Throws an exception"],a:"Done"},
{n:75,q:"How can you safely remove elements from a collection while iterating over it in Java?",c:["By using the collection's 'remove' method","By using an Iterator and calling 'remove'","By modifying the collection directly","By cloning the collection first"],a:"By using an Iterator and calling 'remove'"},
{n:76,q:"Which of the following statements about the relationship between loops and exception handling in Java is correct?",c:["Exceptions cannot be caught inside a loop","Throwing exceptions inside loops can degrade performance","Try-catch blocks cannot be used inside loops","Exceptions are ignored inside loops"],a:"Throwing exceptions inside loops can degrade performance"},
{n:77,q:"In Java, what is the impact of using a 'finally' block in conjunction with a 'break' statement inside a loop?",c:["The 'finally' block is executed before exiting the loop","The 'finally' block is skipped","Causes a compilation error","The 'finally' block is executed after the method returns"],a:"The 'finally' block is executed before exiting the loop"},
{n:78,q:"How does Java's HotSpot JVM optimize loops during runtime?",c:["By interpreting all bytecode as-is","By performing just-in-time compilation and optimizations like loop unrolling","By converting loops to recursive methods","No optimizations are performed"],a:"By performing just-in-time compilation and optimizations like loop unrolling"},
{n:79,q:"Which of the following best describes an Iterator's 'fail-fast' behavior in Java?",c:["It allows concurrent modifications safely","It throws a ConcurrentModificationException if the collection is modified","It continues iteration despite modifications","It prevents any modifications to the collection"],a:"It throws a ConcurrentModificationException if the collection is modified"},
{n:80,q:"What is the effect of using 'parallelStream()' on a small dataset in Java?",c:["Always improves performance","May introduce overhead and reduce performance","Causes a compilation error","Has no effect compared to 'stream()'"],a:"May introduce overhead and reduce performance"},
{n:81,q:"In Java, what is a potential issue with using nested loops over large collections?",c:["Stack overflow errors","Increased time complexity leading to performance issues","Compilation errors","No observable issues"],a:"Increased time complexity leading to performance issues"},
{n:82,q:"How can the use of 'Map.forEach()' improve performance over traditional loops in Java 8 and above?",c:["By allowing parallel execution","By reducing overhead associated with iterator creation","By optimizing for specific data types","It does not improve performance"],a:"By reducing overhead associated with iterator creation"},
{n:83,q:"What will be the output of the following Java code?\n\nint a = 0;\nint b = 5;\nwhile(a < b) {\n System.out.print(a + " ");\n a = ++a;\n}",c:["0 2 4","0 1 2 3 4","1 2 3 4 5","0 1 2 3 4 5"],a:"0 1 2 3 4"},
{n:84,q:"Which of the following practices can help avoid memory leaks in loops when working with IO streams in Java?",c:["Using static variables","Closing streams inside the loop","Deferring stream closure until after the loop","Ignoring exceptions"],a:"Closing streams inside the loop"},
{n:85,q:"In Java, what is the purpose of the 'Spliterator' interface concerning loops and streams?",c:["To split tasks for parallel execution","To iterate over collections in reverse","To provide fail-safe iteration","To handle exceptions in streams"],a:"To split tasks for parallel execution"},
{n:86,q:"How does Java's 'enhanced for-loop' handle arrays compared to collections?",c:["It uses an index internally for arrays","It cannot iterate over arrays","It converts arrays to lists","It treats them the same as collections"],a:"It uses an index internally for arrays"},
{n:87,q:"What will be the output of the following Java code?\n\nList list = Arrays.asList("A", "B", "C");\nfor(String s : list) {\n s = s.toLowerCase();\n}\nSystem.out.println(list);",c:["[a, b, c]","[A, B, C]","[null, null, null]","Compilation error"],a:"[A, B, C]"},
{n:88,q:"Which of the following is a characteristic of a 'foreach' method in Java's Streams API?",c:["Processes elements in parallel by default","Is terminal operation that processes each element","Requires elements to be processed in order","Cannot be used with lambda expressions"],a:"Is terminal operation that processes each element"},
{n:89,q:"In Java, what is the result of using a loop variable outside its scope after the loop has completed?",c:["The variable retains its last value","Compilation error due to undefined variable","The variable is reset to default value","Runtime exception"],a:"Compilation error due to undefined variable"},
{n:90,q:"How does loop tiling improve cache performance in Java applications?",c:["By splitting data into blocks that fit into cache","By merging multiple loops","By increasing loop iterations","By reducing code size"],a:"By splitting data into blocks that fit into cache"},
{n:91,q:"What is the main benefit of using the 'IntStream' over a traditional 'for' loop when processing numerical ranges in Java?",c:["Simplifies code and enables parallel processing","Improves memory usage","Allows use of primitive data types","Increases execution time"],a:"Simplifies code and enables parallel processing"},
{n:92,q:"Which of the following describes the difference between 'Iterator' and 'ListIterator' in Java when used in loops?",c:["'ListIterator' allows bidirectional traversal","'Iterator' allows modification during iteration","Both are functionally identical","'ListIterator' can only traverse forward"],a:"'ListIterator' allows bidirectional traversal"},
{n:93,q:"What will be the output of the following Java code?\n\nString[] arr = {"one", "two", "three"};\nfor(int i = arr.length - 1; i >= 0; i--) {\n System.out.print(arr[i] + " ");\n}",c:["three two one","one two three","Compilation error","ArrayIndexOutOfBoundsException"],a:"three two one"},
{n:94,q:"In Java, when would you prefer using a 'do-while' loop over a 'while' loop?",c:["When the loop must execute at least once","When the loop condition is complex","When you need to check the condition before the loop body","There is no practical difference"],a:"When the loop must execute at least once"},
{n:95,q:"How can the use of 'Optional' in Java 8 and above help avoid infinite loops caused by 'null' values?",c:["By providing a default value","By throwing exceptions on 'null'","By wrapping 'null' references safely","It does not help avoid infinite loops"],a:"By wrapping 'null' references safely"},
{n:96,q:"Which of the following is true about exception handling inside Java streams when compared to traditional loops?",c:["Streams handle exceptions the same way","Checked exceptions must be handled differently in streams","Streams cannot handle exceptions","Exception handling is unnecessary in streams"],a:"Checked exceptions must be handled differently in streams"},
{n:97,q:"In Java, what is one of the challenges of using recursive methods to replace loops for large datasets?",c:["Simpler code","Improved stack utilization","Risk of stack overflow errors","Easier debugging"],a:"Risk of stack overflow errors"},
{n:98,q:"What will be the output of the following Java code?\n\nint[] nums = {1, 2, 3, 4, 5};\nint sum = 0;\nfor(int i = 0; i < nums.length; i++) {\n sum += nums[i];\n nums[i] = sum;\n}\nSystem.out.println(Arrays.toString(nums));",c:["[1, 3, 6, 10, 15]","[1, 2, 3, 4, 5]","[1, 1, 1, 1, 1]","[15, 15, 15, 15, 15]"],a:"[1, 3, 6, 10, 15]"},
{n:99,q:"Which of the following statements is true about the Java compiler's ability to optimize tail-recursive methods?",c:["Java compiler automatically optimizes tail-recursion","Tail-recursive methods are converted into loops by the compiler","Java does not support tail-recursion optimization","Tail-recursion is deprecated in Java"],a:"Java does not support tail-recursion optimization"},
{n:100,q:"How does the concept of 'loop coalescing' apply to Java loops, and what is its potential benefit?",c:["Combining adjacent loops to improve cache performance","Splitting loops into smaller ones","Unrolling loops for optimization","Preventing loops from executing"],a:"Combining adjacent loops to improve cache performance"}
]