Java-InterviewQuestions
Java-InterviewQuestions
4. (Tricky) What are the implications of omitting alt attributes for images?
Answer: Screen readers cannot describe the image, impacting accessibility and SEO.
CSS
7. (Difficult) How would you implement a flexbox-based layout for a responsive navbar?
Answer: Use display: flex; and properties like justify-content and align-items for alignment.
8. (Tricky) What is the difference between relative units (em, rem) and absolute units (px, cm)?
Answer: Relative units scale with context; absolute units are fixed regardless of screen size.
Bootstrap
12. (Tricky) What is the difference between btn-primary and btn-outline-primary classes in Bootstrap?
Answer: btn-primary has a filled background, while btn-outline-primary has a transparent background with a
border.
13. (Easy) What are arrow functions, and how are they different from regular functions?
Answer: Arrow functions have a concise syntax and do not bind their own this.
Copy code
15. (Difficult) What are TypeScript decorators, and how do you create one?
Answer: Metadata annotations used to modify classes or methods. Example:
typescript
Copy code
Angular
19. (Difficult) What is Dependency Injection (DI), and how does Angular implement it?
Answer: DI is a design pattern where dependencies are injected into components. Angular provides services
using providers in modules or components.
Core Java
23. (Difficult) What is the difference between abstract classes and interfaces?
Answer: Abstract classes allow defined and undefined methods, while interfaces (before Java 8) allowed only
abstract methods. Interfaces support multiple inheritance.
Spring
32. (Tricky) What are some common pitfalls of using Spring’s @Autowired?
Answer: Circular dependencies and lack of explicit bean definitions.
DevOps
38. (Moderate) What are Java Streams, and how do they differ from collections?
Answer: Streams process data in a functional style and are lazily evaluated, while collections store data.
39. (Difficult) What is a CompletableFuture, and how does it differ from Future?
Answer: CompletableFuture supports non-blocking and chaining operations, unlike Future.
Spring (Continued)
45. (Easy) What is the difference between @Component and @Service annotations?
Answer: Both mark beans, but @Service is semantically intended for business logic.
Hibernate (Continued)
52. (Tricky) How would you optimize a Hibernate query that performs poorly due to N+1 issues?
Answer: Use JOIN FETCH or @EntityGraph to fetch relationships in a single query.
Database and SQL
55. (Difficult) What is the difference between OLTP and OLAP systems?
Answer: OLTP handles transaction-oriented tasks (e.g., banking), while OLAP supports analytical processing
(e.g., data warehousing).
Angular (Continued)
59. (Difficult) What are Angular Guards, and how do you use them?
Answer: Guards control route access. Example: CanActivate prevents unauthorized users from accessing a
route.
60. (Tricky) Explain how Angular uses Zones for change detection.
Answer: Zones monkey-patch asynchronous APIs to trigger change detection after tasks like setTimeout.
61. (Easy) What is the difference between map() and forEach() in JavaScript?
Answer: map() returns a new array, while forEach() executes a function for each element without returning.
DevOps (Continued)
65. (Easy) What is a container, and how does it differ from a virtual machine?
Answer: Containers are lightweight and share the host OS, while VMs include the entire OS.
68. (Tricky) What is blue-green deployment? How would you implement it?
Answer: It’s a zero-downtime deployment strategy where two environments (blue and green) are alternated.
Use Kubernetes services to switch traffic between environments.
Design Patterns
72. (Tricky) How would you implement the Builder pattern for constructing immutable objects?
Answer: Use chained methods in a Builder class to set properties and return the immutable object.
Concurrency in Java
Advanced Topics
Testing
81. (Easy) What is JUnit used for?
Answer: Unit testing Java applications.
84. (Tricky) What are some best practices for writing effective test cases?
Answer: Use meaningful names, isolate dependencies, and cover edge cases.
85. (Easy) What is the difference between a shallow copy and a deep copy in Java?
Answer: A shallow copy copies object references, while a deep copy duplicates the entire object, including
referenced objects.
86. (Moderate) What are WeakHashMaps in Java? How do they differ from HashMaps?
Answer: A WeakHashMap uses weak references for keys, allowing them to be garbage collected when no
strong references exist. HashMap uses strong references, preventing garbage collection.
87. (Difficult) How does the Garbage Collector handle circular references in Java?
Answer: Java's Garbage Collector uses algorithms like Mark-and-Sweep that can detect and collect circular
references.
java
Copy code
class Singleton {
private Singleton() {}
if (instance == null) {
synchronized (Singleton.class) {
if (instance == null) {
return instance;
}
}
Spring (Continued)
91. (Difficult) How does Spring manage transactions with nested method calls?
Answer: Nested transactions use propagation behaviors like REQUIRED, REQUIRES_NEW, and NESTED.
92. (Tricky) How would you secure sensitive configuration properties in Spring Boot?
Answer: Use tools like Spring Cloud Config with encryption or the jasypt-spring-boot library to encrypt
sensitive values.
Hibernate (Continued)
94. (Moderate) What is the difference between getCurrentSession and openSession in Hibernate?
Answer: getCurrentSession uses a single session per transaction, while openSession creates a new session
every time.
96. (Tricky) What are dynamic inserts and updates in Hibernate, and when would you use them?
Answer: They only include non-null fields in SQL statements, improving efficiency for sparse data updates.
98. (Moderate) What is the Circuit Breaker pattern, and how does it work?
Answer: Protects services from cascading failures by stopping requests to a failing service after a threshold.
100. (Tricky) How would you implement service discovery in a Kubernetes-based microservices setup?
Answer: Use Kubernetes’ built-in DNS or service mesh tools like Istio to dynamically discover services.
• Objective: Build a dynamic e-commerce platform using Java Spring Boot (backend) and Angular/React
(frontend).
• Features:
• Skills Tested:
• Objective: Create a CRUD-based employee management system using Spring Boot, Hibernate, and
Thymeleaf.
• Features:
• Skills Tested:
• Objective: Design a system to manage hotel reservations using Spring MVC and Hibernate.
• Features:
• Skills Tested:
• Objective: Build a real-time chat application using Java Spring Boot and WebSockets.
• Features:
• Skills Tested:
• Objective: Develop a library system to manage book inventory and user activities using JavaFX for the
frontend and Spring Boot for the backend.
• Features:
• Skills Tested:
• Objective: Create an online exam portal for conducting timed quizzes using Spring Boot and Hibernate.
• Features:
• Skills Tested:
• Objective: Build a task management application using Java Spring Boot and React/Angular.
• Features:
o User authentication and role-based permissions.
• Skills Tested:
• Objective: Design a microservices-based movie ticket booking system using Spring Boot.
• Features:
o Separate services for user management, movie catalog, and ticket booking.
• Skills Tested:
• Objective: Develop a distributed banking system using Spring Boot and Kafka.
• Features:
• Skills Tested:
• Objective: Create an image-sharing platform like Instagram using Spring Boot, Hibernate, and Angular/React.
• Features:
• Skills Tested:
• Junior Developers: Focus on simpler CRUD-based projects like the Library Management System or Employee
Management System.
• Mid-Level Developers: Assign projects like E-Commerce Platform, Task Management Application, or Hotel
Reservation System to test API and database integration.
• Senior Developers: Assign challenging projects like Microservices for Movie Ticket Booking, Banking System,
or Image Sharing Platform to evaluate architectural skills and advanced problem-solving.
Let me know if you need additional details or enhancements for any of these projects!