Java Backend Interview Secrets: Redis Cache Strategies & Spring Boot Startup

This article compiles essential Java backend interview topics, covering Redis cache pitfalls and solutions, Spring Boot initialization steps, common Spring annotations, MyBatis advantages, Git workflow commands, Java exception hierarchy, Java 8 enhancements, HashMap internals, Docker isolation mechanisms, and Jenkins CI/CD pipelines, providing a comprehensive technical reference for developers.

macrozheng
macrozheng
macrozheng
Java Backend Interview Secrets: Redis Cache Strategies & Spring Boot Startup

Company Overtime Policies

Several major manufacturers such as Midea, DJI, and Haier have introduced strict end‑of‑day policies to comply with the EU's 2024 anti‑forced‑labor legislation, which bans products involving forced overtime from being sold in the EU market.

Haier Interview (First Round Passed)

Redis Cache Issues

Cache Avalanche : When a large amount of cached data expires simultaneously or Redis fails, all requests fall back to the database, causing a sudden surge in load that may crash the database.

Cache Breakdown : If a hot key expires, many concurrent requests miss the cache and hit the database, potentially overwhelming it.

Cache Penetration : Requests for data that does not exist in both cache and database lead to repeated database hits under high concurrency.

Solutions

Set random expiration times for cached entries to avoid simultaneous expiry.

Use mutex locks to ensure only one request rebuilds the cache, with timeout handling to prevent deadlocks.

Make cache entries effectively permanent and refresh them asynchronously in the background.

Reject illegal requests at the API layer to prevent malicious cache‑penetration attempts.

Cache empty or default values for missing data to reduce database pressure.

Employ Bloom filters to quickly determine non‑existent keys before querying the database.

Spring Boot Initialization Process

When a Spring Boot application starts, the following steps occur:

Create a SpringApplication instance before invoking run().

Initialize SpringApplicationRunListeners to listen for run events.

Load the ConfigurableEnvironment and add it to the listeners.

Create the ConfigurableApplicationContext as the run method's return object.

Refresh the context, triggering auto‑configuration, bean instantiation, and container setup.

Common Spring Annotations

@Component : Marks a class as a Spring bean.

@ComponentScan : Scans specified packages for components.

@Controller : Specialized @Component for web controllers.

@RestController : Combines @Controller and @ResponseBody to return JSON/XML.

@Repository : Marks data‑access components.

@Bean : Registers a method’s return object as a bean.

@Autowired , @Resource , @Qualifier : Dependency injection mechanisms.

@Value , @ConfigurationProperties : Inject configuration values.

@RequestMapping , @GetMapping , @PostMapping , @PutMapping , @DeleteMapping : Map HTTP requests to handler methods.

@Transactional : Declare transaction boundaries.

@Scheduled : Define scheduled tasks.

MyBatis Characteristics

SQL‑centric programming with XML‑based statements, enabling flexible and decoupled SQL management.

Reduces boilerplate code by over 50% compared with raw JDBC.

Compatible with any JDBC‑supported database.

Seamlessly integrates with Spring for high development efficiency.

Provides mapping tags for ORM between objects and database tables.

Git Workflow

Key terminology:

Workspace – working directory.

Index/Stage – staging area.

Repository – local repository.

Remote – remote repository.

Typical commands:

git pull                # fetch latest remote changes
git add .               # stage all modifications
git commit -m "msg"    # commit staged changes
git push                # push commits to remote

Undoing commits:

git reset --soft HEAD^   # keep changes in index and workspace
git reset --mixed HEAD^  # keep changes only in workspace
git reset HEAD^          # same as --mixed

Undoing a push:

git reset HEAD^          # revert local commit
git push origin branch --force   # force‑push corrected history

Java Exception Hierarchy

All exceptions inherit from Throwable, which has two main subclasses:

Error : Serious problems that applications should not catch (e.g., OutOfMemoryError, StackOverflowError).

Exception : Conditions that applications can handle, divided into:

Checked exceptions (must be declared or caught, e.g., FileNotFoundException).

Unchecked exceptions ( RuntimeException and its subclasses, e.g., NullPointerException).

Java 8 New Features

Lambda expressions for functional programming.

Functional interfaces annotated with @FunctionalInterface.

Stream API for fluent collection processing. Optional to avoid null‑pointer errors.

Method references (e.g., System.out::println).

Default and static methods in interfaces.

Parallel array sorting with Arrays.parallelSort.

Repeatable annotations.

Type annotations (e.g., List<@NonNull String>).

CompletableFuture for advanced asynchronous programming.

Lambda Expressions

Lambda syntax: (parameters) -> expression for single‑statement bodies. (parameters) -> { statements; } for multi‑statement bodies, requiring an explicit return if a value is needed.

Example converting an anonymous Runnable to a lambda:

Thread t = new Thread(() -> System.out.println("Running using lambda"));
 t.start();

Lambda also simplifies collection operations, such as filtering even numbers:

List<Integer> evens = numbers.stream()
    .filter(n -> n % 2 == 0)
    .collect(Collectors.toList());

HashMap Internals

Before JDK 8, HashMap used an array of buckets with linked lists for collisions, leading to O(n) lookup in worst‑case scenarios.

Since JDK 8, when a bucket’s list exceeds eight entries, it is transformed into a red‑black tree, reducing lookup time to O(log n). If the tree size falls below six, it reverts to a linked list.

Docker Isolation

Docker achieves container isolation through:

Namespace isolation (PID, network, mount, IPC, etc.) so each container sees only its own resources.

cgroups for resource limitation and prioritization (CPU, memory, I/O).

Jenkins CI/CD

Jenkins is an open‑source automation server that orchestrates continuous integration (CI) and continuous deployment (CD) pipelines.

Continuous Integration (CI)

Developers push code to Git; Jenkins automatically pulls, builds with Maven, runs unit tests, performs static analysis, and produces artifacts. Failures trigger notifications; successes generate deployable packages.

Continuous Deployment (CD)

Successful CI artifacts are automatically deployed to test, staging, and production environments, often using Docker or Kubernetes for zero‑downtime rollouts.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Dockerci/cdBackend DevelopmentredisGitSpring Boot
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.