Java and Spring Boot: language, JVM and Spring essentials – Server Side interview prep

261 interview-style multiple-choice questions on Java and Spring Boot: language, JVM and Spring essentials, organized by topic: concepts, scenarios, code to read and tradeoffs, each with a short explanation. Learn the 123 key terms with the flashcards first, then test yourself.

Take the practice test · Flashcards · All study tools

What it covers

  1. 8.1 Language basics, types and strings
  2. 8.2 OOP, records, sealed types and generics
  3. 8.3 Exceptions, Optional and resources
  4. 8.4 Collections
  5. 8.5 Streams, lambdas and functional style
  6. 8.6 Concurrency and virtual threads
  7. 8.7 The JVM, memory and garbage collection
  8. 8.8 Build tools, testing and modern Java releases
  9. 8.9 Spring Boot

Key terms

8.1 Language basics, types and strings

Integer overflow
int wraps silently
Integer cache
Boxed -128..127 reused
Switch expression
Arrow cases yield values
var
Local type inference
Text block
Multi-line string literal
Pass by value
References copied
Package-private
Default access level
Compact source file
No class needed for main
Unnamed variable
_ for unused values
Effectively final
Capturable by lambdas
Math.floorMod
Non-negative remainder
Module import
import module java.base

8.2 OOP, records, sealed types and generics

Sealed interface
Closed set of subtypes
Compact constructor
Validates record fields
Record pattern
Deconstructs in matches
Default method
Interface method with body
Inner class leak
Hidden outer reference
Flexible constructor body
Code before super()
Type erasure
Generic types gone at runtime
PECS
Producer extends, consumer super
Invariance
List<Integer> isn't List<Number>
ArrayStoreException
Covariant array misuse
Comparator
External ordering

8.3 Exceptions, Optional and resources

equals/hashCode contract
Equal objects must return equal hash codes
record
Concise immutable data class
Checked exception
Exception that must be caught or declared
Virtual thread
Lightweight JVM-managed thread
Suppressed exception
Close failure attached to main error
Multi-catch
One block, several types
Exception chaining
Wrap with cause
orElseGet
Lazy default
orElseThrow
Clear unwrap intent
Optional.stream
Zero-or-one stream
Helpful NPE
Names the null part
requireNonNull
Fail fast on null
UncheckedIOException
Wraps IOException
ExceptionInInitializerError
Static init failed

8.4 Collections

ArrayList
Resizable array-backed list
HashMap
Hash table map with average O(1) operations
Stream
Lazy pipeline of operations over elements
ConcurrentHashMap
Thread-safe high-concurrency map
removeIf
Safe removal while iterating
Arrays.asList
Fixed-size array view
Unmodifiable view
Read-only, shows changes
Sequenced collection
getFirst, getLast, reversed
floorKey
Greatest key ≤ x
EnumMap
Array-backed enum keys
computeIfAbsent
Multimap idiom
Map.merge
Count or combine values
WeakHashMap
Entries vanish with keys
CopyOnWriteArrayList
Copies on write
Weakly consistent iterator
No CME, may miss changes

8.5 Streams, lambdas and functional style

Supplier
No input, returns value
Method reference
String::length
One-shot stream
Reuse throws
groupingBy
Group into a map
toMap merge
Handles duplicate keys
Stream.toList
Unmodifiable result
flatMap
Flattens nested streams
Short-circuiting
Stops early on infinite streams
Gatherer
Custom intermediate op
takeWhile
Stops at first failure
teeing
Two collectors, one result

8.6 Concurrency and virtual threads

synchronized method
Locks this
Virtual thread executor
One virtual thread per task
Pinning
Virtual thread stuck on carrier
Scoped value
Immutable per-call binding
thenCompose
Chains futures
CompletionException
Thrown by join
Restore interrupt
Thread.currentThread().interrupt()
Carrier thread
Platform thread running virtual threads
invokeAny
First successful result
Safe publication
final fields visible after construction
orTimeout
Fails future after timeout

8.7 The JVM, memory and garbage collection

JVM
Java Virtual Machine that runs bytecode
Bytecode
Platform-independent compiled Java code
Heap
Memory area for objects
G1
Default garbage collector in modern HotSpot JVMs
Metaspace
Class metadata, off-heap
Class loader leak
Old classes can't unload
ZGC
Sub-millisecond pauses
Parallel GC
Throughput collector
MaxRAMPercentage
Heap share of container memory
Heap dump on OOM
Capture the heap at failure
JFR
Built-in low-overhead profiler
C1 and C2
Tiered JIT compilers
Escape analysis
Avoids heap allocation
JMH
Java microbenchmark harness
Native image
Ahead-of-time compiled binary
AOT cache
Faster startup from training run
Compact object headers
8-byte headers
Cleaner
Replaces finalize

8.8 Build tools, testing and modern Java releases

Maven lifecycle
Phases run in order
provided scope
Supplied at runtime
Nearest wins
Maven version mediation
BOM
Aligns related versions
Gradle wrapper
Pinned Gradle version
api vs implementation
Leaks vs internal deps
SNAPSHOT
Changing pre-release version
ParameterizedTest
One test, many inputs
LTS cadence
Every two years
jlink
Custom runtime image
Markdown Javadoc
/// comments
JSpecify
Standard nullness annotations
Jakarta EE
javax renamed to jakarta

8.9 Spring Boot

Spring Boot
Opinionated framework for running Spring apps quickly
Bean
Object managed by the Spring container
Auto-configuration
Spring Boot setting up beans based on the classpath
Actuator
Production monitoring endpoints for Spring Boot
@SpringBootApplication
Config, auto-config, scanning
Relaxed binding
SPRING_DATASOURCE_URL
@RestControllerAdvice
Global exception handling
ResponseEntity
Status, headers, body
RestClient
Fluent sync HTTP client
@HttpExchange
Declarative HTTP clients
SecurityFilterChain
Security rules bean
@EnableScheduling
Turns on @Scheduled
Virtual threads property
spring.threads.virtual.enabled
@WebMvcTest
Web-layer slice test
MockMvc
Test MVC without a server
@ServiceConnection
Auto-wire Testcontainers
bootBuildImage
Buildpack OCI image
Spring Boot 4
Framework 7, Jackson 3

Sample practice questions

  1. What does this print? ```java String a = new String("hi"); String b = new String("hi"); System.out.println(a == b); System.out.println(a.equals(b)); ```

    1. `false` then `false`
    2. `true` then `true`
    3. `true` then `false`
    4. `false` then `true`

    Answer: D. `false` then `true` `==` compares references, so two distinct `String` objects aren't `==`; `equals` compares their contents, which match.

  2. If you override `equals` in a Java class, what else must you override?

    1. `hashCode`, so equal objects share a hash code
    2. `compareTo`, so equal objects sort to the same spot
    3. `finalize`, so equal objects are collected together
    4. `toString`, so equal objects print the same text

    Answer: A. `hashCode`, so equal objects share a hash code Breaking the equals/hashCode contract makes objects "disappear" in hash collections.

  3. What is the difference between checked and unchecked exceptions in Java?

    1. Checked exceptions can never be caught; they always terminate the thread
    2. There's no difference; the terms are used interchangeably in Java
    3. Checked ones must be caught or declared; `RuntimeException` subclasses needn't be
    4. Unchecked ones must be caught or declared; checked ones are verified at runtime

    Answer: C. Checked ones must be caught or declared; `RuntimeException` subclasses needn't be `IOException` is checked; `NullPointerException` is unchecked.

  4. What is the difference between `ArrayList` and `LinkedList` for random access by index?

    1. Both `get(i)` calls are O(1), since both are indexed
    2. `LinkedList.get(i)` is O(1); `ArrayList.get(i)` is O(n)
    3. `ArrayList.get(i)` is O(1); `LinkedList.get(i)` is O(n)
    4. Both `get(i)` calls are O(log n), using binary search

    Answer: C. `ArrayList.get(i)` is O(1); `LinkedList.get(i)` is O(n) `ArrayList` is the right default for most lists.

  5. What is a key property of Java streams?

    1. They always run in parallel across all available CPU cores
    2. Intermediate operations are lazy until a terminal one like `collect`
    3. They can be reused again after a terminal operation has run
    4. They load and store every element in memory before processing

    Answer: B. Intermediate operations are lazy until a terminal one like `collect` A stream can be consumed only once.

  6. What are virtual threads (Project Loom, Java 21)?

    1. Special threads that aren't allowed to perform blocking calls
    2. Threads simulated on one OS thread using callbacks, like Node.js
    3. JVM-managed lightweight threads that let blocking code scale hugely
    4. Threads that the JVM offloads to run on the GPU for extra speed

    Answer: C. JVM-managed lightweight threads that let blocking code scale hugely They let simple thread-per-request code handle high concurrency.

  7. What does "write once, run anywhere" rely on?

    1. Portable bytecode that any JVM can run
    2. Running Java only inside web browsers
    3. Compiling directly to every CPU's machine code
    4. Interpreting Java source code on every run

    Answer: A. Portable bytecode that any JVM can run The JVM's JIT compiler turns hot bytecode into native code.

  8. What is the difference between Maven and Gradle?

    1. Maven is used to run the application in production, not to build it
    2. Both build and manage dependencies; Maven uses XML, Gradle a Groovy/Kotlin DSL
    3. Gradle is a build tool for Python projects, not for Java ones
    4. Maven compiles Java code, while Gradle can only run the test suites

    Answer: B. Both build and manage dependencies; Maven uses XML, Gradle a Groovy/Kotlin DSL Both download dependencies from repositories like Maven Central.

  9. What does Spring Boot add on top of the Spring Framework?

    1. A built-in relational database engine for persistence
    2. A replacement for the JVM that runs Spring natively
    3. A new JVM programming language for writing Spring apps
    4. Auto-configuration, starters and an embedded server

    Answer: D. Auto-configuration, starters and an embedded server `spring-boot-starter-web` brings in everything for a web app.

  10. What does `final` mean on a Java local variable or field?

    1. The referenced object becomes deeply immutable as well
    2. It's assigned once; the referenced object can still be mutable
    3. The variable is safely shared across threads without locks
    4. The variable is garbage collected right after its last use

    Answer: B. It's assigned once; the referenced object can still be mutable `final List<String> list` can still have items added.

Practice all 261 questions

More Server Side