Three questions from the bank, with answers. The practice test draws different ones each time.
Question 1 · concurrency · junior
What is the difference between ExecutorService.execute() and ExecutorService.submit()?
A.execute() executes tasks synchronously on the calling thread, while submit() runs tasks asynchronously.
B.execute() returns void and swallows unhandled exceptions, whereas submit() returns a Future that captures task exceptions.
C.execute() returns a Future object, while submit() returns void.
D.execute() accepts Callable tasks, while submit() accepts Runnable tasks.
Show answer
B. execute() returns void and swallows unhandled exceptions, whereas submit() returns a Future that captures task exceptions.
execute(Runnable) is defined in Executor and returns void; uncaught exceptions inside the task trigger the thread's uncaught exception handler. submit() is defined in ExecutorService, accepts Runnable or Callable, and returns a Future<?> that encapsulates task execution results or uncaught exceptions (re-thrown upon calling Future.get()).
Question 2 · jvm · junior
Which reference type in Java allows an object to be Garbage Collected ONLY when the JVM is running low on memory?
A.WeakReference
B.SoftReference
C.PhantomReference
D.StrongReference
Show answer
B. SoftReference
SoftReference objects are collected by the Garbage Collector only as a response to memory demand (i.e., when memory is low before an OutOfMemoryError occurs), making them ideal for memory-sensitive caches. WeakReference objects, in contrast, are garbage collected during the next GC cycle regardless of memory pressure.
Question 3 · spring-basics · junior
What is the primary purpose of Spring Boot Auto-Configuration?
A.To automatically compile Java code into bytecode whenever files are saved.
B.To automatically create database tables without needing SQL schema files.
C.To generate REST API endpoints dynamically for all classes in the project.
D.To automatically configure Spring beans based on libraries present on the classpath and application properties.
Show answer
D. To automatically configure Spring beans based on libraries present on the classpath and application properties.
Spring Boot Auto-Configuration attempts to automatically configure a Spring application based on jar dependencies detected on the classpath and user properties. For example, if h2 and spring-boot-starter-data-jpa are present, Spring Boot automatically configures an in-memory database and EntityManagerFactory without requiring manual bean declarations.