0% found this document useful (0 votes)
9 views5 pages

Java Backend Interview Round3

The document provides a comprehensive set of interview questions and answers for a Java Backend Developer role, covering topics such as Java, Spring Boot, microservices architecture, cloud deployment, CI/CD pipelines, and database management. It includes practical coding examples and explanations of various concepts like exception handling, validation, and deployment strategies. Additionally, it discusses monitoring tools and techniques for ensuring high availability and disaster recovery in cloud environments.

Uploaded by

kiransai3699
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Java Backend Interview Round3

The document provides a comprehensive set of interview questions and answers for a Java Backend Developer role, covering topics such as Java, Spring Boot, microservices architecture, cloud deployment, CI/CD pipelines, and database management. It includes practical coding examples and explanations of various concepts like exception handling, validation, and deployment strategies. Additionally, it discusses monitoring tools and techniques for ensuring high availability and disaster recovery in cloud environments.

Uploaded by

kiransai3699
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Java Backend Developer

Interview Questions, Answers & Code Samples


Cloud/DevOps • Architecture • Spring Boot • Java Core • Coding

💼 Project & Experience


Q Explain your Java + Spring Boot experience.
● Built RESTful microservices using Spring Boot with layered architecture (Controller, Service,
Repository).
● Integrated Spring Security (JWT/OAuth2), Spring Data JPA, and Spring Cloud components.
● Worked on event-driven systems using Kafka for async communication.

Q Explain your microservices architecture.


● Each service is independently deployable with its own database (Database-per-service pattern).
● Services communicate via REST (sync) or Kafka (async).
● API Gateway handles routing, auth, and rate limiting.
● Service discovery via Eureka or GCP-native DNS.

Q How do microservices communicate?


Synchronous: REST (HTTP/HTTPS), gRPC
Asynchronous: Kafka, Pub/Sub, RabbitMQ
Async preferred for decoupling; sync for real-time responses.

Q Explain your PayPal project.


● Payment processing microservice integrated with PayPal REST SDK.
● Handled order creation, payment capture, refunds with idempotency keys to prevent duplicates.
● Secured with OAuth2 client credentials flow; all PII encrypted at rest and in transit.

☁️ Cloud / DevOps Questions


Q How do you deploy backend services in GCP?
● Containerize service with Docker, push image to Artifact Registry.
● Deploy to Cloud Run (serverless) or GKE (Kubernetes) via CI/CD pipeline.

Q What services do you use in Google Cloud?


Compute: Cloud Run, GKE, Compute Engine
Storage: Cloud Storage, Cloud SQL, Firestore
Messaging: Pub/Sub
Security: IAM, Secret Manager, Cloud Armor
Observability: Cloud Monitoring, Cloud Logging, Trace

Q Explain Cloud Run.


▶ Serverless container platform on GCP. Automatically scales from 0 to N instances based on HTTP
traffic. No infrastructure management needed. Billed per request.

Q Explain Cloud Storage buckets (inbound, outbound, archive).


● Inbound — receives raw/uploaded files (write-only for producers).
● Outbound — processed/ready-to-serve files (read for consumers).
● Archive — long-term cold storage with lower cost; Nearline/Coldline/Archive storage classes.

Q How do you deploy code to QA?


● Push code to feature branch → PR triggers CI pipeline (build + tests).
● On merge to develop/QA branch, CD pipeline deploys container to QA Cloud Run service.

Q Explain CI/CD pipeline.


CI: Code push → Build → Unit Tests → Code Quality (SonarQube) → Docker Image
CD: Push image to registry → Deploy to QA → Integration Tests → Deploy to Prod
Tools: Jenkins, GitHub Actions, Cloud Build, ArgoCD.

Q Difference between CI and CD.


CI: Continuous Integration — automate build & test on every commit
CD: Continuous Delivery/Deployment — automate release to environments

Reliability / Architecture Questions


Q How do you design cross-cloud portable services?
● Use Docker containers (cloud-agnostic runtime).
● Avoid vendor-specific SDKs in core logic; wrap them in adapter interfaces.
● Use Kubernetes for orchestration (runs on GCP/AWS/Azure).
● Externalize config using environment variables or config maps.

Q How do you handle high availability?


● Deploy across multiple availability zones.
● Use load balancer to distribute traffic.
● Implement health checks and auto-restart policies.
● Use Circuit Breaker to prevent cascade failures.

Q How do you handle disaster recovery?


● Regular automated DB backups with point-in-time recovery.
● Multi-region deployment with failover routing (Cloud DNS / Traffic Director).
● Define RTO (Recovery Time Objective) and RPO (Recovery Point Objective) targets.

Q Do you know Blue-Green deployment?


▶ Two identical environments: Blue (live) and Green (new version). Switch traffic to Green after testing.
Instant rollback by reverting traffic to Blue. Zero downtime.
Q Do you know Canary deployment?
▶ Gradually route a small percentage of traffic (e.g. 5%) to the new version. Monitor metrics. If stable,
increase to 100%. Minimizes blast radius of bad releases.

📊 Monitoring / Observability
Q What tools do you use for monitoring?
● GCP: Cloud Monitoring, Cloud Logging, Cloud Trace, Error Reporting.
● App-level: Spring Boot Actuator, Micrometer, Prometheus + Grafana.
● APM: Dynatrace, Datadog.

Q Do you know Actuator endpoints?


/actuator/health: Service health status (UP/DOWN), DB connectivity, disk space
/actuator/metrics: JVM memory, CPU, HTTP request counts, latency histograms
/actuator/info: Application metadata (version, build, git commit)

Q Have you used Dynatrace / monitoring tools?


● Dynatrace auto-instruments JVM apps, traces distributed requests end-to-end.
● Creates service dependency maps and detects anomalies automatically.

Database Questions
Q Which databases did you use?
● MySQL — transactional OLTP workloads, relational data.
● PostgreSQL — advanced SQL features, JSONB, full-text search.
● MongoDB — document store for flexible/hierarchical data.

Q Have you used MongoDB?


● Used Spring Data MongoDB with @Document, @MongoRepository.
● Aggregation pipelines for complex analytics queries.

Q How do you handle DB performance issues?


● Add indexes on frequently queried columns (avoid full table scans).
● Use query explain plans to identify slow queries.
● Enable connection pooling (HikariCP).
● Use pagination (@Pageable) instead of fetching all records.
● Caching with Redis/Caffeine for repeated read queries.
● Partition or shard tables for 10M+ records.

Spring Boot / Backend Coding


Q Create REST API to save data into database (with validation & exception handling).
Entity:
@Entity
public class User {
@Id @GeneratedValue(strategy = [Link])
private Long id;
@NotBlank private String name;
@Email private String email;
}

Controller:
@RestController @RequestMapping("/api/users")
public class UserController {
@PostMapping
public ResponseEntity<User> save(@Valid @RequestBody User user) {
return [Link]([Link](user));
}
}

Global Exception Handler:


@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler([Link])
public ResponseEntity<Map<String,String>> handleValidation(
MethodArgumentNotValidException ex) {
Map<String,String> errors = new HashMap<>();
[Link]().getFieldErrors()
.forEach(e -> [Link]([Link](), [Link]()));
return [Link]().body(errors);
}
}

Q What is @RestControllerAdvice?
▶ Combines @ControllerAdvice + @ResponseBody. Intercepts exceptions thrown by any
@RestController and returns structured JSON error responses globally.

Q How does @Valid @RequestBody validation work?


● @Valid triggers Bean Validation (JSR-380) on the incoming request body.
● Annotations like @NotBlank, @Email, @Size on the model fields define rules.
● Violations throw MethodArgumentNotValidException, caught by @ExceptionHandler.

☕ Java Core Questions


Q Types of exceptions in Java.
Checked: Must be declared/caught at compile time. E.g. IOException, SQLException
Unchecked: RuntimeException subclasses. E.g. NullPointerException, IllegalArgumentException
Error: JVM-level, not catchable. E.g. OutOfMemoryError, StackOverflowError
Q How to create custom exceptions.
Checked custom exception:
public class PaymentException extends Exception {
public PaymentException(String msg) { super(msg); }
}
Unchecked custom exception:
public class ResourceNotFoundException extends RuntimeException {
public ResourceNotFoundException(String msg) { super(msg); }
}

Q How to handle validation errors.


● Use @Valid with @RequestBody in controller.
● Catch MethodArgumentNotValidException in @RestControllerAdvice.
● Extract field errors from BindingResult and return 400 Bad Request.

🧩 Coding Question
Q Find the first non-repeating character in a string.
Example: Input: "swiss" Output: 'w'

Solution (LinkedHashMap preserves insertion order):


public char firstNonRepeating(String s) {
Map<Character, Integer> freq = new LinkedHashMap<>();
for (char c : [Link]())
[Link](c, 1, Integer::sum);
for ([Link]<Character, Integer> e : [Link]())
if ([Link]() == 1) return [Link]();
return '\0'; // no non-repeating char
}

Time Complexity: O(n) — two passes over the string


Space Complexity: O(1) — at most 26 entries in the map (fixed alphabet)

Trace for "swiss":


● s → 2, w → 1, i → 1
● First character with count 1 → 'w' ✓

You might also like