Skip to main content

Paytm Java Developer Interview Questions & Answers

This guide covers real-world technical interview questions asked during the first round of a Paytm Java Developer interview. The candidate had 3 years of experience. The interview focused heavily on Spring Boot internals, REST API optimization, reactive programming (WebFlux), Microservices architecture, and debugging core Java code snippets.


1. Spring Boot Internals & Configuration

Q: What are Conditional Annotations in Spring Boot? Give an example.

A: Conditional annotations are special instructions that tell Spring Boot to execute a piece of code or register a bean only if specific conditions are met.

  • Example: @ConditionalOnClass. This tells Spring Boot to load a specific bean only if a particular class is present on the application's classpath.
  • Purpose: They provide fine-grained control over configuration, make the application highly flexible across different environments, and increase efficiency by ensuring unnecessary beans are not initialized, saving memory and startup time.

Q: Explain the role of @EnableAutoConfiguration. How does Spring Boot achieve this internally?

A: @EnableAutoConfiguration tells Spring Boot to automatically configure the application based on the dependencies present in the pom.xml. For example, if it sees spring-boot-starter-web, it automatically configures an embedded Tomcat server and Spring MVC without manual XML setup.

  • Internal Working: It achieves this through Classpath Scanning. It inspects the libraries loaded in the project's classpath at runtime. It reads the META-INF/spring.factories (or auto-configure imports) file, which contains a list of auto-configuration classes, and uses @Conditional annotations to determine which default beans should be injected.

Q: Are you aware of Actuator endpoints? How can we secure them?

A: Yes, Actuator exposes operational endpoints (like /health, /metrics, /env) to monitor and manage the application in production. The dependency is spring-boot-starter-actuator. Securing them:

  1. Limit Exposure: Expose only safe endpoints (like /health) and hide sensitive ones via the application.properties file (management.endpoints.web.exposure.include).
  2. Spring Security: Require authentication by integrating Spring Security.
  3. Role-Based Access: Create a specific role (e.g., ACTUATOR_ADMIN) and map it to these endpoints so standard users cannot access them.
  4. HTTPS: Ensure the endpoints are served over a secure, encrypted connection.

Q: How do Spring Boot Profiles work? Why use .yml over .properties?

A: Profiles allow developers to separate and manage configurations for different environments (e.g., dev, qa, prod). You can define a test database in the dev profile and a real database in the prod profile, activating them using spring.profiles.active=prod.

  • Why .yml: YAML files are widely preferred because they offer a clean, hierarchical, tree-like structure using indentation. This vastly improves readability for deeply nested configurations and natively supports lists and maps, unlike flat .properties files.

Q: What is the default embedded server provided by Spring Boot? Can we change it?

A: The default server is Apache Tomcat. Yes, it can be easily changed. You simply exclude the spring-boot-starter-tomcat dependency from the spring-boot-starter-web package in your pom.xml, and add the dependency for your preferred server, such as spring-boot-starter-jetty or undertow.

Q: What is @ComponentScan and how would you prevent a specific package from being scanned?

A: @ComponentScan tells Spring to scan the current package and its sub-packages for Spring components (@Component, @Service, @Repository) to register them in the Application Context. To exclude a specific package, you use the excludeFilters attribute: @ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = "com.paytm.exclude.*"))


2. API Optimization, AOP & Reactive Programming

Q: What strategies would you use to optimize the performance of a Spring Boot application?

A: 1. Caching (Redis): Cache frequently accessed, read-heavy data to reduce database hits. 2. Database Optimization: Optimize SQL queries, use appropriate indexing, and configure connection pooling (HikariCP). 3. Asynchronous Processing: Use @Async for non-blocking background operations like sending emails. 4. Load Balancing: Distribute high traffic across multiple server instances. 5. Code Optimization: Improve algorithms to reduce time complexity (e.g., $O(n^2)$ to $O(n \log n)$). 6. Reactive Programming: Transition to Spring WebFlux to handle massive concurrent connections efficiently.

Q: What is Spring WebFlux? Can you provide a real-world analogy?

A: Spring WebFlux is a reactive, non-blocking web framework used to build highly responsive APIs capable of handling massive concurrent traffic using a very small number of threads.

  • Analogy: In a traditional restaurant (Spring MVC), a cashier takes your order, waits doing nothing until the kitchen cooks it, gives you the food, and then takes the next customer's order. The line gets long. In a WebFlux restaurant, the cashier takes your order, passes it to the kitchen, and immediately turns to serve the next customer. When your food is ready, you are asynchronously notified. It handles sudden traffic rushes smoothly without blocking.

Q: What is Aspect-Oriented Programming (AOP) in Spring? Give an advanced use case.

A: AOP is a programming paradigm that separates "cross-cutting concerns" from the main business logic. Instead of repeating code (like logging or security checks) inside every single method, AOP defines this logic once in an Aspect and specifies where it should be applied (using Pointcuts).

  • Advanced Use Case: Authorization/Security. Instead of writing if(user.hasPermission()) inside 50 different controller methods, you write an Aspect that intercepts API requests, performs the security check globally, and either allows execution or blocks it with a 403 Forbidden response. This keeps the controllers perfectly clean.

3. Microservices & System Design

Q: Suppose you need to ensure Zero Downtime Deployments for an e-commerce application. What approach would you take?

A: The standard approaches are:

  1. Blue-Green Deployment: Maintain two identical production environments (Blue and Green). Traffic routes to Blue. You deploy the new version to Green, test it internally, and then instantly switch the router/load balancer to point to Green. If anything fails, you switch right back to Blue.
  2. Canary Deployment: Deploy the new version to a very small subset of live users (e.g., 5% of traffic). If it performs stably without errors, you gradually roll it out to 100%.

Q: How would you design a Zomato/Food Delivery backend from scratch? Design the schema for a Delivery Partner.

A: I would use a Microservices architecture, splitting domains logically:

  1. Microservices: User Authentication Service, Restaurant Catalog Service, Cart/Checkout Service, Payment Gateway Service, and Delivery Tracking Service.
  2. Delivery Partner Schema:
    • partner_id (Primary Key)
    • name, phone_number, email (PII)
    • vehicle_details, driving_license_number
    • current_location_lat, current_location_long (Updated frequently for live tracking)
    • is_available (Boolean flag to check if they are currently delivering an order)

4. Core Java & Code Snippet Debugging

Q: Explain the entry point in Java: public static void main(String[] args).

A: * public: Allows the JVM to access the method from anywhere to start execution.

  • static: Allows the JVM to invoke the method directly without needing to instantiate an object of the class first.
  • void: The method does not return any value to the JVM upon completion.
  • main: The standard, hardcoded method name the JVM searches for.
  • String[] args: An array of strings used to capture and pass command-line arguments into the program.

Q: Time complexity of HashMap vs TreeMap? Is HashMap sorted internally?

A: * HashMap: It is completely unordered and unsorted. Time complexity for insertion, deletion, and retrieval is $O(1)$ (constant time) on average.

  • TreeMap: It keeps data strictly sorted based on the natural ordering of keys. It is backed by a Red-Black Tree, so its time complexity for operations is $O(\log n)$.

Q: Code Snippet 1 (Default Values)

class Test {
int x;
int y;
}
// Inside main:
Test t = new Test();
System.out.println(t.x + " " + t.y);

Output: 0 0 Reason: Instance variables of primitive numeric types (int) are automatically initialized to their default value of 0 when the object is instantiated.

Q: Code Snippet 2 (Loop Condition)

for (int i = 0; 0; i++) {
System.out.println("Hello");
break;
}

Output: Compile-time Error Reason: In Java, unlike C/C++, the condition block of a for loop, while loop, or if statement must strictly evaluate to a boolean (true or false). You cannot use an integer like 0 as a conditional expression.

Q: Code Snippet 3 (Static Context)

public void myFunc() { System.out.println("Func"); }

public static void main(String[] args) {
myFunc();
}

Output: Compile-time Error Reason: You cannot make a static reference to a non-static method. myFunc() belongs to an instance of the class, while main() belongs to the class itself. You must create an object (new MainClass().myFunc()) to call it.

Q: Code Snippet 4 (Varargs)

public void getData(int... data) { ... }

// Inside main:
getData(1, 2, 3);

Output: The method successfully executes. Reason: The int... data syntax is known as Varargs (Variable Arguments). Java treats it internally as an array (int[]). You can pass zero or multiple integer arguments to it, and it will handle them dynamically.