[Go to site: main page, start]

0% found this document useful (0 votes)
2 views10 pages

Java Spring Boot Interview Questions Guide

The document contains a comprehensive list of Java and Spring Boot interview questions covering various topics such as JVM architecture, data structures (HashMap vs TreeMap), dependency injection, auto-configuration, Hibernate caching, microservices patterns, Kafka consumer groups, Docker lifecycle, Kubernetes services, OAuth2 flows, JWT, idempotency, and versioning strategies. Each question is accompanied by a brief explanation and examples to illustrate the concepts. This serves as a valuable resource for preparing for technical interviews in Java and Spring Boot.

Uploaded by

mohit beni
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)
2 views10 pages

Java Spring Boot Interview Questions Guide

The document contains a comprehensive list of Java and Spring Boot interview questions covering various topics such as JVM architecture, data structures (HashMap vs TreeMap), dependency injection, auto-configuration, Hibernate caching, microservices patterns, Kafka consumer groups, Docker lifecycle, Kubernetes services, OAuth2 flows, JWT, idempotency, and versioning strategies. Each question is accompanied by a brief explanation and examples to illustrate the concepts. This serves as a valuable resource for preparing for technical interviews in Java and Spring Boot.

Uploaded by

mohit beni
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 & Spring Boot Interview Questions (Detailed)

Java Core

1. Explain the JVM Architecture.


JVM consists of Class Loader, Runtime Data Areas (Heap, Stack, Method Area, PC Registers,
Native Stack), Execution Engine, and Garbage Collector.
Example: When a Java program runs, bytecode is loaded by the Class Loader, stored in
Method Area; objects go into the Heap; threads maintain their own Stacks.

2. What is the difference between HashMap and TreeMap?


HashMap is unordered, allows null keys/values, uses hashing -> O(1) average operations.
TreeMap is sorted (Red-Black Tree), no null key, operations O(log n).
Example: Use TreeMap when sorted keys matter.

Spring Boot

3. Explain Dependency Injection with an example.


DI allows objects to receive dependencies externally.
Example:
@Service class UserService { @Autowired Repo repo; }
Spring injects Repo instance into UserService.

4. Explain Auto Configuration in Spring Boot.


Spring Boot inspects classpath + configuration files and automatically configures beans.
Example: If spring-boot-starter-web is present, it configures Tomcat, DispatcherServlet
automatically.

Spring Data JPA

5. Explain Hibernate first-level cache.


Session-level cache, enabled by default.
Example: Two findById calls retrieve from cache without hitting DB.

6. Difference between Lazy and Eager loading.


LAZY loads related entities only when accessed.
EAGER loads immediately and can cause N+1 issues.

Microservices

7. Explain Circuit Breaker Pattern.


Prevents cascading failures.
Example: Using Resilience4j, if a service fails repeatedly, breaker trips → fallback logic.
8. Explain service discovery.
Services register with discovery server (Eureka/Consul).
Clients discover others dynamically instead of hardcoding URLs.

Kafka

9. Explain Kafka Consumer Groups.


A group shares consumption of topic partitions.
Example: 3 partitions, 3 consumers → parallel consumption.

10. Explain exactly-once semantics in Kafka.


Uses idempotent producer + transactions to ensure no duplicate messages.

Docker

11. Explain Docker container lifecycle.


create → start → pause → unpause → stop → kill → remove.

12. Explain Dockerfile best practices.


Use minimal base images, multi-stage builds, avoid root user.

Kubernetes

13. Explain Pod vs Deployment.


Pod = smallest deployable unit.
Deployment manages replicas, rolling updates.

14. Explain services in Kubernetes.


ClusterIP, NodePort, LoadBalancer expose Pod networking.

Security

15. Explain OAuth2 Authorization Code Flow.


Browser → Auth Server → Authorization Code → Backend exchanges code for token →
Access API.

16. Explain JWT with example.


JWT = [Link].
Example: Encodes user roles and expiration inside payload.

REST API

17. Explain idempotency with examples.


PUT /user/1 → same result no matter how many times.
POST is not idempotent.
18. Explain versioning strategies.
URL versioning (/v1), header-based, query param versioning.

19. Explain the JVM Architecture.


JVM consists of Class Loader, Runtime Data Areas (Heap, Stack, Method Area, PC Registers,
Native Stack), Execution Engine, and Garbage Collector.
Example: When a Java program runs, bytecode is loaded by the Class Loader, stored in
Method Area; objects go into the Heap; threads maintain their own Stacks.

20. What is the difference between HashMap and TreeMap?


HashMap is unordered, allows null keys/values, uses hashing -> O(1) average operations.
TreeMap is sorted (Red-Black Tree), no null key, operations O(log n).
Example: Use TreeMap when sorted keys matter.

21. Explain Dependency Injection with an example.


DI allows objects to receive dependencies externally.
Example:
@Service class UserService { @Autowired Repo repo; }
Spring injects Repo instance into UserService.

22. Explain Auto Configuration in Spring Boot.


Spring Boot inspects classpath + configuration files and automatically configures beans.
Example: If spring-boot-starter-web is present, it configures Tomcat, DispatcherServlet
automatically.

23. Explain Hibernate first-level cache.


Session-level cache, enabled by default.
Example: Two findById calls retrieve from cache without hitting DB.

24. Difference between Lazy and Eager loading.


LAZY loads related entities only when accessed.
EAGER loads immediately and can cause N+1 issues.

25. Explain Circuit Breaker Pattern.


Prevents cascading failures.
Example: Using Resilience4j, if a service fails repeatedly, breaker trips → fallback logic.

26. Explain service discovery.


Services register with discovery server (Eureka/Consul).
Clients discover others dynamically instead of hardcoding URLs.

27. Explain Kafka Consumer Groups.


A group shares consumption of topic partitions.
Example: 3 partitions, 3 consumers → parallel consumption.
28. Explain exactly-once semantics in Kafka.
Uses idempotent producer + transactions to ensure no duplicate messages.

29. Explain Docker container lifecycle.


create → start → pause → unpause → stop → kill → remove.

30. Explain Dockerfile best practices.


Use minimal base images, multi-stage builds, avoid root user.

31. Explain Pod vs Deployment.


Pod = smallest deployable unit.
Deployment manages replicas, rolling updates.

32. Explain services in Kubernetes.


ClusterIP, NodePort, LoadBalancer expose Pod networking.

33. Explain OAuth2 Authorization Code Flow.


Browser → Auth Server → Authorization Code → Backend exchanges code for token →
Access API.

34. Explain JWT with example.


JWT = [Link].
Example: Encodes user roles and expiration inside payload.

35. Explain idempotency with examples.


PUT /user/1 → same result no matter how many times.
POST is not idempotent.

36. Explain versioning strategies.


URL versioning (/v1), header-based, query param versioning.

37. Explain the JVM Architecture.


JVM consists of Class Loader, Runtime Data Areas (Heap, Stack, Method Area, PC Registers,
Native Stack), Execution Engine, and Garbage Collector.
Example: When a Java program runs, bytecode is loaded by the Class Loader, stored in
Method Area; objects go into the Heap; threads maintain their own Stacks.

38. What is the difference between HashMap and TreeMap?


HashMap is unordered, allows null keys/values, uses hashing -> O(1) average operations.
TreeMap is sorted (Red-Black Tree), no null key, operations O(log n).
Example: Use TreeMap when sorted keys matter.
39. Explain Dependency Injection with an example.
DI allows objects to receive dependencies externally.
Example:
@Service class UserService { @Autowired Repo repo; }
Spring injects Repo instance into UserService.

40. Explain Auto Configuration in Spring Boot.


Spring Boot inspects classpath + configuration files and automatically configures beans.
Example: If spring-boot-starter-web is present, it configures Tomcat, DispatcherServlet
automatically.

41. Explain Hibernate first-level cache.


Session-level cache, enabled by default.
Example: Two findById calls retrieve from cache without hitting DB.

42. Difference between Lazy and Eager loading.


LAZY loads related entities only when accessed.
EAGER loads immediately and can cause N+1 issues.

43. Explain Circuit Breaker Pattern.


Prevents cascading failures.
Example: Using Resilience4j, if a service fails repeatedly, breaker trips → fallback logic.

44. Explain service discovery.


Services register with discovery server (Eureka/Consul).
Clients discover others dynamically instead of hardcoding URLs.

45. Explain Kafka Consumer Groups.


A group shares consumption of topic partitions.
Example: 3 partitions, 3 consumers → parallel consumption.

46. Explain exactly-once semantics in Kafka.


Uses idempotent producer + transactions to ensure no duplicate messages.

47. Explain Docker container lifecycle.


create → start → pause → unpause → stop → kill → remove.

48. Explain Dockerfile best practices.


Use minimal base images, multi-stage builds, avoid root user.

49. Explain Pod vs Deployment.


Pod = smallest deployable unit.
Deployment manages replicas, rolling updates.

50. Explain services in Kubernetes.


ClusterIP, NodePort, LoadBalancer expose Pod networking.
51. Explain OAuth2 Authorization Code Flow.
Browser → Auth Server → Authorization Code → Backend exchanges code for token →
Access API.

52. Explain JWT with example.


JWT = [Link].
Example: Encodes user roles and expiration inside payload.

53. Explain idempotency with examples.


PUT /user/1 → same result no matter how many times.
POST is not idempotent.

54. Explain versioning strategies.


URL versioning (/v1), header-based, query param versioning.

55. Explain the JVM Architecture.


JVM consists of Class Loader, Runtime Data Areas (Heap, Stack, Method Area, PC Registers,
Native Stack), Execution Engine, and Garbage Collector.
Example: When a Java program runs, bytecode is loaded by the Class Loader, stored in
Method Area; objects go into the Heap; threads maintain their own Stacks.

56. What is the difference between HashMap and TreeMap?


HashMap is unordered, allows null keys/values, uses hashing -> O(1) average operations.
TreeMap is sorted (Red-Black Tree), no null key, operations O(log n).
Example: Use TreeMap when sorted keys matter.

57. Explain Dependency Injection with an example.


DI allows objects to receive dependencies externally.
Example:
@Service class UserService { @Autowired Repo repo; }
Spring injects Repo instance into UserService.

58. Explain Auto Configuration in Spring Boot.


Spring Boot inspects classpath + configuration files and automatically configures beans.
Example: If spring-boot-starter-web is present, it configures Tomcat, DispatcherServlet
automatically.

59. Explain Hibernate first-level cache.


Session-level cache, enabled by default.
Example: Two findById calls retrieve from cache without hitting DB.

60. Difference between Lazy and Eager loading.


LAZY loads related entities only when accessed.
EAGER loads immediately and can cause N+1 issues.
61. Explain Circuit Breaker Pattern.
Prevents cascading failures.
Example: Using Resilience4j, if a service fails repeatedly, breaker trips → fallback logic.

62. Explain service discovery.


Services register with discovery server (Eureka/Consul).
Clients discover others dynamically instead of hardcoding URLs.

63. Explain Kafka Consumer Groups.


A group shares consumption of topic partitions.
Example: 3 partitions, 3 consumers → parallel consumption.

64. Explain exactly-once semantics in Kafka.


Uses idempotent producer + transactions to ensure no duplicate messages.

65. Explain Docker container lifecycle.


create → start → pause → unpause → stop → kill → remove.

66. Explain Dockerfile best practices.


Use minimal base images, multi-stage builds, avoid root user.

67. Explain Pod vs Deployment.


Pod = smallest deployable unit.
Deployment manages replicas, rolling updates.

68. Explain services in Kubernetes.


ClusterIP, NodePort, LoadBalancer expose Pod networking.

69. Explain OAuth2 Authorization Code Flow.


Browser → Auth Server → Authorization Code → Backend exchanges code for token →
Access API.

70. Explain JWT with example.


JWT = [Link].
Example: Encodes user roles and expiration inside payload.

71. Explain idempotency with examples.


PUT /user/1 → same result no matter how many times.
POST is not idempotent.

72. Explain versioning strategies.


URL versioning (/v1), header-based, query param versioning.

73. Explain the JVM Architecture.


JVM consists of Class Loader, Runtime Data Areas (Heap, Stack, Method Area, PC Registers,
Native Stack), Execution Engine, and Garbage Collector.
Example: When a Java program runs, bytecode is loaded by the Class Loader, stored in
Method Area; objects go into the Heap; threads maintain their own Stacks.

74. What is the difference between HashMap and TreeMap?


HashMap is unordered, allows null keys/values, uses hashing -> O(1) average operations.
TreeMap is sorted (Red-Black Tree), no null key, operations O(log n).
Example: Use TreeMap when sorted keys matter.

75. Explain Dependency Injection with an example.


DI allows objects to receive dependencies externally.
Example:
@Service class UserService { @Autowired Repo repo; }
Spring injects Repo instance into UserService.

76. Explain Auto Configuration in Spring Boot.


Spring Boot inspects classpath + configuration files and automatically configures beans.
Example: If spring-boot-starter-web is present, it configures Tomcat, DispatcherServlet
automatically.

77. Explain Hibernate first-level cache.


Session-level cache, enabled by default.
Example: Two findById calls retrieve from cache without hitting DB.

78. Difference between Lazy and Eager loading.


LAZY loads related entities only when accessed.
EAGER loads immediately and can cause N+1 issues.

79. Explain Circuit Breaker Pattern.


Prevents cascading failures.
Example: Using Resilience4j, if a service fails repeatedly, breaker trips → fallback logic.

80. Explain service discovery.


Services register with discovery server (Eureka/Consul).
Clients discover others dynamically instead of hardcoding URLs.

81. Explain Kafka Consumer Groups.


A group shares consumption of topic partitions.
Example: 3 partitions, 3 consumers → parallel consumption.

82. Explain exactly-once semantics in Kafka.


Uses idempotent producer + transactions to ensure no duplicate messages.

83. Explain Docker container lifecycle.


create → start → pause → unpause → stop → kill → remove.
84. Explain Dockerfile best practices.
Use minimal base images, multi-stage builds, avoid root user.

85. Explain Pod vs Deployment.


Pod = smallest deployable unit.
Deployment manages replicas, rolling updates.

86. Explain services in Kubernetes.


ClusterIP, NodePort, LoadBalancer expose Pod networking.

87. Explain OAuth2 Authorization Code Flow.


Browser → Auth Server → Authorization Code → Backend exchanges code for token →
Access API.

88. Explain JWT with example.


JWT = [Link].
Example: Encodes user roles and expiration inside payload.

89. Explain idempotency with examples.


PUT /user/1 → same result no matter how many times.
POST is not idempotent.

90. Explain versioning strategies.


URL versioning (/v1), header-based, query param versioning.

91. Explain the JVM Architecture.


JVM consists of Class Loader, Runtime Data Areas (Heap, Stack, Method Area, PC Registers,
Native Stack), Execution Engine, and Garbage Collector.
Example: When a Java program runs, bytecode is loaded by the Class Loader, stored in
Method Area; objects go into the Heap; threads maintain their own Stacks.

92. What is the difference between HashMap and TreeMap?


HashMap is unordered, allows null keys/values, uses hashing -> O(1) average operations.
TreeMap is sorted (Red-Black Tree), no null key, operations O(log n).
Example: Use TreeMap when sorted keys matter.

93. Explain Dependency Injection with an example.


DI allows objects to receive dependencies externally.
Example:
@Service class UserService { @Autowired Repo repo; }
Spring injects Repo instance into UserService.

94. Explain Auto Configuration in Spring Boot.


Spring Boot inspects classpath + configuration files and automatically configures beans.
Example: If spring-boot-starter-web is present, it configures Tomcat, DispatcherServlet
automatically.
95. Explain Hibernate first-level cache.
Session-level cache, enabled by default.
Example: Two findById calls retrieve from cache without hitting DB.

96. Difference between Lazy and Eager loading.


LAZY loads related entities only when accessed.
EAGER loads immediately and can cause N+1 issues.

97. Explain Circuit Breaker Pattern.


Prevents cascading failures.
Example: Using Resilience4j, if a service fails repeatedly, breaker trips → fallback logic.

98. Explain service discovery.


Services register with discovery server (Eureka/Consul).
Clients discover others dynamically instead of hardcoding URLs.

99. Explain Kafka Consumer Groups.


A group shares consumption of topic partitions.
Example: 3 partitions, 3 consumers → parallel consumption.

100. Explain exactly-once semantics in Kafka.


Uses idempotent producer + transactions to ensure no duplicate messages.

You might also like