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
- 8.1 Language basics, types and strings
- 8.2 OOP, records, sealed types and generics
- 8.3 Exceptions, Optional and resources
- 8.4 Collections
- 8.5 Streams, lambdas and functional style
- 8.6 Concurrency and virtual threads
- 8.7 The JVM, memory and garbage collection
- 8.8 Build tools, testing and modern Java releases
- 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
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)); ```
- `false` then `false`
- `true` then `true`
- `true` then `false`
- `false` then `true`
Answer: D. `false` then `true` `==` compares references, so two distinct `String` objects aren't `==`; `equals` compares their contents, which match.
If you override `equals` in a Java class, what else must you override?
- `hashCode`, so equal objects share a hash code
- `compareTo`, so equal objects sort to the same spot
- `finalize`, so equal objects are collected together
- `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.
What is the difference between checked and unchecked exceptions in Java?
- Checked exceptions can never be caught; they always terminate the thread
- There's no difference; the terms are used interchangeably in Java
- Checked ones must be caught or declared; `RuntimeException` subclasses needn't be
- 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.
What is the difference between `ArrayList` and `LinkedList` for random access by index?
- Both `get(i)` calls are O(1), since both are indexed
- `LinkedList.get(i)` is O(1); `ArrayList.get(i)` is O(n)
- `ArrayList.get(i)` is O(1); `LinkedList.get(i)` is O(n)
- 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.
What is a key property of Java streams?
- They always run in parallel across all available CPU cores
- Intermediate operations are lazy until a terminal one like `collect`
- They can be reused again after a terminal operation has run
- 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.
What are virtual threads (Project Loom, Java 21)?
- Special threads that aren't allowed to perform blocking calls
- Threads simulated on one OS thread using callbacks, like Node.js
- JVM-managed lightweight threads that let blocking code scale hugely
- 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.
What does "write once, run anywhere" rely on?
- Portable bytecode that any JVM can run
- Running Java only inside web browsers
- Compiling directly to every CPU's machine code
- 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.
What is the difference between Maven and Gradle?
- Maven is used to run the application in production, not to build it
- Both build and manage dependencies; Maven uses XML, Gradle a Groovy/Kotlin DSL
- Gradle is a build tool for Python projects, not for Java ones
- 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.
What does Spring Boot add on top of the Spring Framework?
- A built-in relational database engine for persistence
- A replacement for the JVM that runs Spring natively
- A new JVM programming language for writing Spring apps
- 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.
What does `final` mean on a Java local variable or field?
- The referenced object becomes deeply immutable as well
- It's assigned once; the referenced object can still be mutable
- The variable is safely shared across threads without locks
- 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.
More Server Side
- HTTP fundamentals
- REST API design
- GraphQL
- gRPC & real-time APIs
- OAuth 2.0, OIDC & JWT
- Sessions, cookies & web app security
- C# & .NET
- Node.js & Express
- Python, Django & FastAPI
- Go (Golang)
- Concurrency & multithreading
- OOP & SOLID
- Design patterns
- Dependency injection
- Logging & observability
- Data structures
- Algorithms & Big-O
- Linux & shell scripting