Java & Spring Quick Reference

One page of the essentials: Java collections and concurrency choices, modern Java by version, Spring annotations by purpose, transaction propagation and isolation, Spring Boot test slices, security defaults, resilience settings, and current versions.

On this page

Java choices#

NeedUse
ListArrayList
LookupHashMap / HashSet
Sorted or range queriesTreeMap / TreeSet
Queue or stackArrayDeque
Thread-safe mapConcurrentHashMap (computeIfAbsent, merge)
Producer–consumerBlockingQueue
Counter under contentionLongAdder
Blocking I/O fan-outVirtual threads (newVirtualThreadPerTaskExecutor)
CPU-bound parallel workA fixed pool ≈ cores, or ForkJoinPool
Async compositionCompletableFuture (always pass an executor)
Context passingScoped values (Java 25), else ThreadLocal

Modern Java by version#

VersionHighlights
17 LTSSealed classes, records (16), pattern-matching instanceof (16), text blocks (15)
21 LTSVirtual threads, record patterns, pattern-matching switch, sequenced collections, generational ZGC
22–24Unnamed _, FFM API, stream gatherers, no synchronized pinning (24)
25 LTSFlexible constructor bodies, module imports, compact source files, scoped values, compact object headers
26HTTP/3 client, warnings for reflective final mutation
27 (Sept 2026)G1 the default everywhere, post-quantum hybrid TLS key exchange; previews continue

Spring annotations by purpose#

PurposeAnnotations
Beans@Component, @Service, @Repository, @Configuration, @Bean, @Primary, @Qualifier, @Lazy, @Scope, @Profile
Lifecycle@PostConstruct, @PreDestroy, SmartLifecycle
Config@ConfigurationProperties, @Value, @ConfigurationPropertiesScan
Conditions@ConditionalOnClass, @ConditionalOnMissingBean, @ConditionalOnProperty, @ConditionalOnWebApplication
Web@RestController, @GetMapping…, @PathVariable, @RequestParam, @RequestBody, @Valid, @RestControllerAdvice, @ExceptionHandler
Data@Entity, @Id, @ManyToOne(fetch = LAZY), @Query, @EntityGraph, @Transactional, @Version, @Lock
Cache@EnableCaching, @Cacheable, @CachePut, @CacheEvict
Events and async@EventListener, @TransactionalEventListener, @Async, @Scheduled
Security@EnableWebSecurity, @EnableMethodSecurity, @PreAuthorize, @PostAuthorize
ResilienceSpring 7: @Retryable, @ConcurrencyLimit; Resilience4j: @CircuitBreaker, @Retry, @Bulkhead, @RateLimiter
Observability@Observed, @Timed
Testing@SpringBootTest, @WebMvcTest, @DataJpaTest, @MockitoBean, @ServiceConnection, @WithMockUser

Transactions#

PropagationBehaviour
REQUIRED (default)Join or create
REQUIRES_NEWSuspend, create a new one (second connection)
NESTEDSavepoint
SUPPORTS / NOT_SUPPORTED / NEVER / MANDATORYJoin-if-present / suspend / fail-if-present / fail-if-absent

Rollback on RuntimeException and Error by default. Proxies apply only to public methods called from outside the bean. Default isolation: READ COMMITTED (PostgreSQL, Oracle, SQL Server), REPEATABLE READ (MySQL).

Test slices#

SliceLoads
@WebMvcTestMVC + security filters for the given controllers
@DataJpaTestJPA + repositories + migrations (rolled back)
@JsonTestJackson
@RestClientTestHTTP client + a mock server
@SpringBootTestEverything

Security defaults to remember#

  • Deny by default: anyRequest().authenticated() last.
  • CSRF on for cookie sessions; off only for bearer-token APIs.
  • JWT: validate signature, iss, aud and exp.
  • Authorization code + PKCE; a BFF for SPAs; client credentials between services.
  • Object-level checks against BOLA.

Resilience starting values#

SettingTypical start
HTTP connect / read timeout1 s / 2–5 s (within the caller’s budget)
Retries2–3, exponential backoff from 100–200 ms, with jitter, idempotent calls only
Circuit breaker50% failure or slow-call rate over 20–50 calls, open for 30 s, 5 half-open trials
BulkheadConcurrent calls ≈ the dependency’s capacity share

Versions (November 2026)#

Java 25 LTS (27 latest) · Spring Boot 4.1 (4.2 due Nov 2026) · Spring Framework 7 · Spring Security 7 · Spring Cloud 2025.1 (Oakwood) · Hibernate ORM 7 · JUnit 6 · Kafka 4.2.