← Back to list

Capgemini Java Developer Interview Experience — 4

Interview of a candidate with 4+ years of Experience

Shivam Srivastava in Coding Odyssey · 2025-10-13 19:14 · 33 claps · 9.1 min read paywalled
#java #technology #programming #software-development #software-engineering
Open on Medium ↗
Wiki topics: LLM · Large Language Models 💻 · Programming

Capgemini Java Developer Interview Experience — 4

Interview of a candidate with 4+ years of Experience

If you are not a paid member of Medium, please use my friend link to read the entire article: Friend Link

One of my followers, recently, appeared for the Capgemini interview for Java developer role.

For context, he has over 4 years of experience in Java, SQL, Spring Boot, Microservices, and related technologies.

I’ll break this down in 2 parts:

  1. Interview Process
  2. Interview Questions

This is how it went:

1. Interview Process:

The process was smooth and as follows:

  • He got an call from Capgemini HR team regarding an opening.
  • He shared the requested details with the HR team.
  • After sharing the details, the first technical round was setup.

On the day of the interview:

  • The interviewer joined the call on time.
  • They exchanged pleasantries and got straight into technical questions.
  • The interviewer were professional and courteous throughout.

2. Interview Questions:

Below are some of the technical questions he was asked. I’ve merged similar questions and follow-up queries for clarity.

I’ll include textbook explanations for all the answers to help anyone preparing for interviews.

Q1. What is Immutability in Java? How to create an Immutable class in Java?

I have already written a detailed article on the Immutable Classes in Java. Request you to please go through the same:

[embed]Immutable Classes in Java: Deep Dive with Interview Questions A Deep Dive Into What, Why, and How with Code Breakdownmedium.com

Q2. Write a program to find the second largest number from a list using Java 8.

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class SecondLargest {
    public static void main(String[] args) {
        List<Integer> numbers = Arrays.asList(5, 2, 9, 1, 7, 9, 3);
        int secondLargest = numbers.stream()
                .distinct() // remove duplicates
                .sorted(Comparator.reverseOrder()) // sort in descending order
                .skip(1) // skip the largest element
                .findFirst() // get the next element
                .orElseThrow(() -> new IllegalArgumentException("List must have at least two distinct elements"));
        System.out.println("Second largest number: " + secondLargest);
    }
}

Explanation:

  1. **distinct()** → removes duplicate numbers.
  2. **sorted(Comparator.reverseOrder())** → sorts in descending order.
  3. **skip(1)** → skips the first (largest) element.
  4. **findFirst()** → fetches the second largest element.
  5. **orElseThrow()** → handles the case where the list has fewer than two unique numbers.

Example Output:

Second largest number: 7

Alternative Approach (Using max and filter):

int max = numbers.stream().max(Integer::compareTo).get();
int secondMax = numbers.stream()
                       .filter(n -> n < max)
                       .max(Integer::compareTo)
                       .get();
System.out.println("Second largest number: " + secondMax);

Q3. What is a Functional Interface? Explain with code on how to create one.

A Functional Interface is an interface that contains exactly one abstract method.

It can have any number of default or static methods, but only one abstract method defines its functional behavior.

Functional Interfaces are the backbone of Lambda Expressions in Java 8. They allow you to write cleaner and more concise code.

Features:

  • Introduced in Java 8.
  • Can be annotated with @FunctionalInterface (optional but recommended).
  • Examples in Java: Runnable, Callable, Comparator, Function, Predicate, Consumer, etc.
  • Enables functional programming in Java.

Example: Creating a Functional Interface

@FunctionalInterface
interface Calculator {
    int operate(int a, int b);  // single abstract method
}

Now, you can use this interface with a Lambda Expression:

public class FunctionalInterfaceExample {
    public static void main(String[] args) {
        // Using Lambda Expression
        Calculator add = (a, b) -> a + b;
        Calculator multiply = (a, b) -> a * b;
System.out.println("Addition: " + add.operate(5, 3));
        System.out.println("Multiplication: " + multiply.operate(5, 3));
    }
}

Explanation:

  • The interface Calculator has one abstract method → operate().
  • You can create different implementations using lambda expressions without writing separate classes.
  • The @FunctionalInterface annotation helps the compiler ensure that only one abstract method exists.

Output:

Addition: 8
Multiplication: 15

Q4. How to create a Spring Boot REST application which can perform CRUD operations from scratch?

I have already written a detailed article on this topic. Request you to please go through the same:

[embed]Create a Spring Boot Rest API Project From Scratch For Beginnersmedium.com

Q5. Explain all annotations used in the above Spring Boot REST application?

Let’s break down the annotations layer by layer, exactly as used in the Spring Boot REST API project:

Main Class:

**@SpringBootApplication:**

It’s a convenience annotation that combines three annotations:

  • @Configuration → Marks the class as a source of bean definitions.
  • @EnableAutoConfiguration → Enables Spring Boot’s auto-configuration mechanism.
  • @ComponentScan → Scans for Spring components (like @Controller, @Service, @Repository) in the current package and sub-packages.

It tells Spring Boot: “This is my entry point, wire up everything automatically.”

Controller Layer:

**@RestController:**

  • A combination of @Controller + @ResponseBody.
  • Marks the class as a RESTful controller that handles HTTP requests.
  • Automatically converts method return values into JSON or XML (via Jackson).

**@RequestMapping("/api/users"):**

  • Defines the base URL path for all endpoints inside this controller.
  • Every endpoint method inherits this base path (e.g., /api/users/{id}).

**@GetMapping, @PostMapping, @PutMapping, @DeleteMapping:**

Shortcut annotations for mapping HTTP methods:

  • @GetMapping → for GET requests (read/fetch).
  • @PostMapping → for POST requests (create).
  • @PutMapping → for PUT requests (update).
  • @DeleteMapping → for DELETE requests (remove).

These make REST endpoints cleaner and more readable than the older @RequestMapping(method = RequestMethod.GET) syntax.

**@PathVariable:**

  • Binds a value from the URL path to a method parameter. Example: /api/users/{id}@PathVariable Long id

**@RequestBody:**

  • Maps the JSON body from an HTTP request to a Java object. Used in POST and PUT methods to receive input data.

**@Autowired:**

  • Enables dependency injection.
  • Spring automatically creates and injects the required bean into the annotated field, constructor, or setter.
  • Used in UserController to inject UserService.

Service Layer:

**@Service:**

  • Marks the class as a Service Component in the Spring context.
  • It’s used to write business logic and also makes the class eligible for component scanning.

**@Autowired:**

  • Injects UserRepository into the UserService class so you can perform database operations.

Repository Layer:

**@Repository:**

Marks the class as a Data Access Layer component. Specialization of @Component that helps with:

  • Automatic exception translation — converts database exceptions into Spring’s DataAccessException.
  • Component scanning (so Spring can find and manage it).

Model Layer (Entity):

**@Entity:**

  • Marks the class as a JPA Entity (maps to a database table).
  • Each instance represents a row in that table.

**@Table(name = "users"):**

  • Specifies the table name in the database that this entity maps to.

**@Id:**

  • Marks the primary key field of the entity.

**@GeneratedValue(strategy = GenerationType.IDENTITY):**

  • Specifies how the primary key should be generated.
  • IDENTITY means the database will auto-increment the ID (common in PostgreSQL/MySQL).

**@Column:**

Defines the properties of a database column:

  • nullable = false → the column cannot be null.
  • unique = true → ensures unique values in that column.

Lombok Annotations:

**@Getter and @Setter**

  • Automatically generate getter and setter methods for all fields.
  • Reduce boilerplate code and make the entity cleaner.

Q6. Explain the steps to deploy this application in production environment.

Below is the step-by-step explanation for deploying a Spring Boot REST API application to a production environment:

Step 1: Build the Application

Use Maven or Gradle to package the application.

  • Command for Maven:
mvn clean package
  • This creates a fat JAR (e.g., myapp-0.0.1-SNAPSHOT.jar) containing all dependencies.

Step 2: Choose the Deployment Environment

Decide where to host your application:

  • Cloud platforms: AWS (EC2, ECS), Azure, GCP
  • On-premises server
  • Containerized environment: Docker/Kubernetes

Step 3: Configure Environment Variables

Set up environment-specific configurations for production (like DB URL, credentials, API keys).

You can use:

  • application-prod.properties or application-prod.yml
  • Environment variables (SPRING_PROFILES_ACTIVE=prod)

Example:

export SPRING_PROFILES_ACTIVE=prod
export DB_URL=jdbc:mysql://prod-db:3306/mydb
export DB_USER=root
export DB_PASS=securepass

Step 4: Database Setup

  • Ensure your production database is ready and accessible.
  • Apply any Flyway or Liquibase migrations to create/update schema.
mvn flyway:migrate -Dflyway.configFiles=src/main/resources/flyway-prod.conf

Step 5: Deployment of Application

Option 1: Deploy JAR directly

java -jar myapp-0.0.1-SNAPSHOT.jar

Option 2: Deploy via Docker

  • Create a Dockerfile:
FROM openjdk:17-jdk-alpine
COPY target/myapp-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
  • Build and run:
docker build -t myapp:prod .
docker run -d -p 8080:8080 --env-file .env myapp:prod

Option 3: Deploy via Cloud Services

  • AWS Elastic Beanstalk: Upload the JAR or Docker image
  • Kubernetes: Create a Deployment and Service YAML

Step 6: Configure Reverse Proxy / Load Balancer

Use Nginx, Apache, or AWS ALB to handle:

  • HTTPS (SSL/TLS)
  • Routing requests to the application
  • Load balancing between multiple instances

Example Nginx config:

server {
    listen 80;
    server_name myapi.example.com;location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Step 7: Monitoring and Logging

  • Configure production-ready logging using logback-spring.xml or external logging (ELK stack, Splunk).
  • Set up monitoring/alerts using Prometheus/Grafana or CloudWatch.

Step 8: Security & Performance

  • Enable HTTPS.
  • Set up authentication and authorization (JWT, OAuth2, or API keys).
  • Tune JVM options for production:
java -Xms512m -Xmx2g -jar myapp.jar

Step 9: CI/CD Automation

  • Use Jenkins, GitHub Actions, or GitLab CI/CD for automated builds, tests, and deployments.
  • Example pipeline steps:
  1. Build → mvn clean package
  2. Run unit & integration tests
  3. Build Docker image
  4. Push to registry
  5. Deploy to production

Q7. What is Profiles in Spring Boot?

Profiles in Spring Boot allow you to define environment-specific configurations and beans, so your application can behave differently in development, testing, staging, or production environments.

How Profiles Work:

  1. You create property files for each environment:
  • application-dev.properties → Development
  • application-test.properties → Testing
  • application-prod.properties → Production
  1. You can also define environment-specific beans using the @Profile annotation.

Example: Properties

application-dev.properties:

server.port=8081
spring.datasource.url=jdbc:mysql://localhost:3306/devdb

application-prod.properties:

server.port=8080
spring.datasource.url=jdbc:mysql://prod-db:3306/proddb

Example: Beans

@Configuration
@Profile("dev")
public class DevConfig {
    @Bean
    public DataSource dataSource() {
        return new HikariDataSource(); // Development DB
    }
}

@Configuration
@Profile("prod")
public class ProdConfig {
    @Bean
    public DataSource dataSource() {
        return new HikariDataSource(); // Production DB
    }
}

Activating a Profile

You can activate a profile in multiple ways:

  1. application.properties
spring.profiles.active=dev

2. Environment variable

export SPRING_PROFILES_ACTIVE=prod

3. Command line argument

java -jar myapp.jar --spring.profiles.active=prod

Benefits:

  • Keep environment-specific settings separate.
  • Avoid hardcoding sensitive info in code.
  • Simplify testing and deployment across environments.
  • Enable conditional beans only in required environments.

Q8. Explain some components from microservices architecture.

In a microservices architecture, an application is broken into small, independent services — each handling a specific business capability.

These services communicate with each other through APIs and are designed for scalability, resilience, and flexibility.

Here are the key components:

1. API Gateway:

  • Acts as the single entry point for all client requests.
  • Handles authentication, routing, load balancing, and rate limiting.
  • Example: Spring Cloud Gateway, Kong, NGINX.

2. Service Registry:

  • Keeps track of all running microservices and their locations (IP/port).
  • Helps with service discovery — so services can find each other dynamically.
  • Example: Eureka, Consul, Zookeeper.

3. Configuration Server:

  • Centralized place to manage configuration for all microservices.
  • Makes deployment easier — you don’t need to rebuild services for config changes.
  • Example: Spring Cloud Config Server.

4. Inter-Service Communication:

  • Services talk to each other using REST APIs, gRPC, or message brokers.
  • Synchronous → HTTP/REST
  • Asynchronous → Kafka, RabbitMQ

5. Database per Service:

  • Each service has its own database to maintain loose coupling.
  • Can use different types — SQL or NoSQL — based on service needs.

6. Load Balancer:

  • Distributes traffic across multiple instances of a service for better performance and fault tolerance.
  • Example: Ribbon, NGINX, AWS ELB.

7. Monitoring and Logging:

  • Essential for tracking health, performance, and debugging issues.
  • Tools: Prometheus, Grafana, ELK Stack (Elasticsearch, Logstash, Kibana), Zipkin for distributed tracing.

8. Circuit Breaker:

  • Prevents cascading failures by stopping calls to a failing service temporarily.
  • Example: Resilience4j, Hystrix.

Q9. Explain API Gateway in detail.

I have already written a detailed article on API gateway. Request you to please go through the same:

[embed]API Gateway with Spring Boot: Deep Dive with Interview Questions A Comprehensive Guidemedium.com

Q10. Explain Service Discovery in detail.

I have already written a detailed article on Service Discovery. Request you to please go through the same:

[embed]Service Discovery: Deep Dive with Interview Questions A Comprehensive Guidemedium.com

Q11. How do microservices communicate with each other?

Microservices can communicate synchronously or asynchronously, depending on the use case and system design.

1. Synchronous Communication:

In synchronous communication, one service calls another and waits for the response before proceeding.

Think of it like a normal phone call — one talks, the other listens, and replies instantly.

Common Protocols:

  • HTTP/REST → Most common.

Example:

@RestController
public class OrderController {
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/place-order")
    public String placeOrder() {
        String paymentResponse = restTemplate.getForObject("http://PAYMENT-SERVICE/pay", String.class);
        return "Order placed: " + paymentResponse;
    }
}
  • gRPC → High-performance binary protocol using HTTP/2; great for internal service communication.
  • GraphQL → Used when clients need flexible querying.

Tools/Libraries:

  • RestTemplate, WebClient (Spring WebFlux)
  • Feign Client (used in Spring Cloud)
  • gRPC stubs for strongly-typed communication

Pros:

  • Simple to implement and debug
  • Direct request-response model

Cons:

  • Tight coupling between services
  • Failure in one service can cascade (handled using Circuit Breakers)

2. Asynchronous Communication:

In asynchronous communication, services communicate without waiting for an immediate response.

It’s more like sending a WhatsApp message — you send it and move on; the reply can come later.

Common Technologies:

Message Brokers like:

  • RabbitMQ
  • Apache Kafka
  • AWS SQS
  • Google Pub/Sub

Example:

Order Service → sends message → Kafka Topic → Payment Service consumes it later.

// Producer
kafkaTemplate.send("payment-topic", orderDetails);

// Consumer
@KafkaListener(topics = "payment-topic", groupId = "payment-group")
public void processPayment(String orderDetails) {
    // Process payment asynchronously
}

Pros:

  • Decoupled services
  • More resilient (messages can be retried)
  • Better scalability

Cons:

  • Complex debugging
  • Eventual consistency (no immediate response)

Final Thoughts:

The interview was pretty straight forward and very much in line with what you would expect from Capgemini.

Candidate cleared this round and then second technical round was setup for him.

If you or someone you know recently had an interview or if you’d like me to explain any topic, feel free to reach out to me via email. I’ll write an detailed article on the same.

If you need help with interview preparation, or need consultation in general. Please reach out to me over the email.

Email: shivamsrivastava.iec@gmail.com

For collaboration, clarifications or support please connect with me on:

Email: shivamsrivastava.iec@gmail.com

Quora: Shivam Srivastava

X.com (Twitter): Shivam on X

Buy Me a Coffee: Shivam Srivastava

If you liked this article, you’ll also enjoy my below list of articles:

[embed]Deep Dive Series Edit descriptionmedium.com

[embed]Interview Experiences and Learnings Edit descriptionmedium.com


메타데이터
post_id
4e4b396d9b93
slug
capgemini-java-developer-interview-experience-4-4e4b396d9b93
url
https://medium.com/coding-odyssey/capgemini-java-developer-interview-experience-4-4e4b396d9b93
canonical_url
https://medium.com/coding-odyssey/capgemini-java-developer-interview-experience-4-4e4b396d9b93
author_url
https://medium.com/@shivamsrivastava.iec
status
ok
fetched_at
2026-06-12 18:14:10