Infosys Java Interview | 4 to 7 Years | Java | Microservices | Database | Spring Boot
📺 This post is based on a real mock interview discussion. All answers are paraphrased and structured for learning purposes.
🔗 Video credit: CloudTech – Watch here
Q1: Can you tell me about your project architecture?
Answer:
The project transitioned from monolithic to microservices architecture. It uses Zuul as the API Gateway, and Consul (previously Eureka) for service discovery. Each microservice registers itself with the discovery server. The architecture supports client-side load balancing and uses both relational (e.g., MySQL) and NoSQL (MongoDB) databases.
Q2: How do microservices communicate with each other?
Answer:
-
Synchronous communication: Uses FeignClient (earlier RestTemplate).
-
Asynchronous communication: Uses Kafka. Events are published and consumed across services without waiting for a reply.
Q3: What features are implemented in the API Gateway?
Answer:
-
Authentication and Authorization
-
Rate Limiting (returns HTTP 429 on too many requests)
-
Response Aggregation from multiple services
Q4: What design patterns and SOLID principles do you follow?
Answer:
-
Design Patterns: Singleton, Strategy, Builder
-
SOLID Principles:
-
S: Single Responsibility
-
O: Open/Closed Principle
-
L: Liskov Substitution
-
I: Interface Segregation
-
D: Dependency Inversion (handled via Spring's Dependency Injection)
-
Q5: How do you structure a Spring Boot CRUD application?
Answer:
-
Layers: Controller → Service → Repository
-
Annotations:
@RestController
,@Service
,@Repository
-
HTTP Methods:
GET
,POST
,PUT
,DELETE
-
Status Codes: 200 (OK), 201 (Created), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found)
Q6: What is your packaging structure?
Answer:
Uses base package like com.cloudtech.projectname
with sub-packages for controller, service, repository, and separate folders for resources and test cases.
Q7: How do you connect your Spring Boot app with a database?
Answer:
Using application.properties
to define database url
, username
, and password
. Spring Boot auto-configures the datasource.
Q8: How do you optimize a slow-performing API?
Answer:
-
Check network latency
-
Analyze SQL query logic
-
Ensure proper indexing on filter/join columns
Q9: What is the purpose of indexing in databases?
Answer:
Indexes speed up queries by avoiding full table scans. Instead of scanning each row, the database uses the index to directly fetch relevant rows.
Q10: What types of joins exist in SQL?
Answer:
-
Inner Join: Returns matching rows from both tables.
-
Left Outer Join: Returns all rows from the left table, and matched rows from the right.
-
Right Outer Join: Returns all rows from the right table, and matched rows from the left.
-
Full Outer Join: Returns all rows from both tables, matched or not.
Q11: Which Java version do you use and what are Java 8 features?
Answer:
Using Java 11 with Java 8 features like:
-
Functional Interfaces
-
Lambda Expressions
-
Streams API
-
Date/Time API
-
StringJoiner
Q12: How to filter employees aged over 60 using Streams?
Answer:
List<Employee> seniorEmployees = employees.stream()
.filter(e -> e.getAge() > 60)
.collect(Collectors.toList());
Q13: How do you handle exceptions in Java?
Answer:
Use try-catch
blocks or throws
keyword. For cleanup, use finally
block.
Q14: Types of Exceptions?
Answer:
-
Checked Exceptions: Must be handled at compile time (e.g., IOException).
-
Unchecked Exceptions: Runtime issues like NullPointerException, IndexOutOfBoundsException.
Q15: When is finally
block not executed?
Answer:
-
When JVM shuts down via
System.exit()
-
When fatal errors like OutOfMemoryError occur
Q16: What is a deadlock and how to avoid it?
Answer:
-
Deadlock: Two threads wait indefinitely for resources held by each other.
-
Prevention: Avoid nested locking or use timeout mechanisms.
Q17: What are wait()
and notify()
in Java?
Answer:
Used for inter-thread communication, like in producer-consumer problems. wait()
releases lock and pauses thread, notify()
wakes a waiting thread.
Q18: Difference between HashMap and ConcurrentHashMap?
Answer:
-
HashMap: Not thread-safe, suitable for single-threaded apps.
-
ConcurrentHashMap: Thread-safe using segmented locks, ideal for concurrent apps.
Q19: Difference between ArrayList and LinkedList?
Answer:
-
ArrayList: Fast for random access, backed by array.
-
LinkedList: Fast for insert/delete, backed by nodes with references.
Q20: Difference between SQL and NoSQL databases?
Answer:
-
SQL: Structured schema, uses SQL for queries (e.g., MySQL).
-
NoSQL: Schema-less, good for flexible data formats (e.g., MongoDB)
💡 Conclusion
This mock interview covers real-world Java backend development scenarios including Spring Boot, microservices, exception handling, and Java 8 features. Ideal for preparing INFOSYS and other enterprise-level backend developer roles.
📺 Inspired by CloudTech’s interview video. Watch here: https://www.youtube.com/watch?v=TNEfRtkla_0
👍 Drop a comment if you’d like more breakdowns like this or want to practice your own interview answers!
0 Comments