Interview Questions
Interview Questions
What is polymorphism?
type of inheritance
what is encapsulation
what is inheritance
Collection Framework
<------------------------------------------------------------------------------------------------>
exception vs error
what is IOC
JPA/JDBC
if you have number of fields to store into DB then how you can do?
What is micro-service?
170.Which case would you prefer LinkedList and which case Arraylist ?
178.What is synchronization?
181.Explain functional interface and what are some of the available interfaces?
--------------------------------------------------------------------------------------------------------------------------------------
New Ques: -
1. What happen when two different java object have same hash-code in hash-map and how did
you handel such a scenerios.
4. How does JVM handle the memory leak and what tools and technic you use to identify and
fix the memory leak in application.
5. What is Jprofiler, eclips memory anilizer, visual – tools for memory leak fix.
11. What make an object immutable, scenerio where using immutable object would be
advantage over the mutable.
14. Need to secure the RestAPI in spring boot application what security method would you
consider and why.
15. How does spring boot autoConfiguration mechanism work or can we override this.
16. If you want to scale you spring boot application for high traffic what spring boot feature you
levrage.
18. If you were task with ensuring high availability for a spring boot ecomerce application during
peak time what archictural decision would you make.
New Ques: -
Aspects of Spring that you have used in your project- Spring data-JPA-JDBC-Hibernate-, Spring boot,
SPRING cloud, Security, Spring AMQP- for Rabbit MQ, Spring WEB Flux - webclient, MVC - to render
Appropriate view
SOLID Principles
@ExceptionHandler (CustomNotFoundException.class)
public ResponseMsg handleNotFoundException(CustomNotFoundException ex) {
return new ResponseMsg(ex.getMessage());
}
}
----------------------------------------------------------------------------------------------------------------
The Saga Pattern is a design pattern used to manage data consistency across multiple
microservices in a distributed system. It ensures that a series of related operations either all
succeed or all fail, maintaining consistency without using traditional database transactions,
which can be difficult in microservices architecture.
Key Concepts
1. Saga: A sequence of transactions that updates each service and publishes a message
or event to trigger the next transaction step.
2. Compensating Transactions: If a step in the sequence fails, a series of compensating
transactions are executed to undo the changes made by previous transactions,
ensuring the system returns to a consistent state.
3. Choreography and Orchestration: Two approaches to implement the Saga Pattern.
Choreography
In this approach, each service involved in the saga listens for events and decides when to
execute its transaction and publish the next event. It is a decentralized approach where
there is no central controller.
Advantages:
o Simpler implementation.
o No single point of failure.
Disadvantages:
o Harder to manage and debug as the number of services increases.
o Complex event handling.
In an e-commerce system, when a customer places an order, the following services might be
involved:
Orchestration
In this approach, a central coordinator (orchestrator) tells each service what local
transaction to execute. The orchestrator also handles failures by instructing services to
perform compensating transactions.
Advantages:
o Easier to manage and debug.
o Centralized control and coordination.
Disadvantages:
o The orchestrator can become a single point of failure.
o More complex to implement initially.
In a travel booking system, you need to book a flight, hotel, and car rental. The orchestrator
coordinates these steps:
1. Book Flight: The orchestrator sends a request to the Flight Service to book a flight.
2. Book Hotel: If the flight booking is successful, the orchestrator sends a request to
the Hotel Service to book a hotel.
3. Book Car Rental: If the hotel booking is successful, the orchestrator sends a request
to the Car Rental Service to book a car rental.
4. Compensation: If any step fails, the orchestrator triggers compensating transactions
to cancel previous bookings.
Strangler:
this pattern involves gradually replacing an old system with a new one.
In software terms, you create a new system that coexists with the old one. You slowly move features
from the old system to the new one, piece by piece. A special layer (like a traffic controller) directs
users to either the old or new parts depending on what's been migrated. Over time, the new system
grows and 'strangles' the old one until it's no longer needed.
This approach is great because it's less risky than replacing everything at once. You can test each
new part as you go, and if something goes wrong, you can easily switch back to the old system. It's
especially useful for big, complex systems that can't afford downtime or where a complete overhaul
would be too risky or expensive
Reduced Risk: By incrementally replacing the old system, you minimize the risk of major
failures that could occur with a big-bang migration.
Continuous Improvement: Allows for continuous delivery of new features and
improvements.
User Experience: Users experience a seamless transition with minimal disruption.
Flexibility: The approach is flexible and can be adapted to various system architectures and
requirements.
Example Scenario
Imagine you have an old e-commerce website built with outdated technology. You want to move to
a modern platform without shutting down the site. Here's how you might use the Strangler Pattern:
1. Identify Parts to Replace: Start with a non-critical component, like the user login module.
2. Build in Parallel: Develop a new login module using modern technology and host it alongside
the old system.
3. Redirect Traffic: Use a proxy server to route login requests to the new module, while the
rest of the site continues to use the old system.
4. Retire Old Component: Once the new login module is stable and fully functional, deactivate
the old login functionality.
Repeat this process for other components, like the product catalog, shopping cart, and payment
system, until the entire e-commerce platform has been modernized.
1 GraphQL:
2 WebSocket:
3 SOAP:
4 MQTT:
--------------------------------------------------------------------------------------------------------------------------------------
---------------------------------
Creational
Singleton
Factory
Interface Shape {
void getname();
sysout("circle");
sysout("Squre");
sysout("Triangle");
if(name.equals("circle"))
if(name.equals("squar"))
if(name.equals("triangle"))
main()
s1.getname();
Builder –
@builder
---------------------------------
Behavioural
Null Object Method is a Behavioural Design Pattern, it is used to handle the absence of a valid object
by providing an object that does nothing or provides default behaviour.
------------------------------------
Adapter
Scenario: When you have existing code or components with interfaces that are incompatible with the
interfaces expected by new code or systems.
Need: The Adapter pattern allows you to integrate existing components seamlessly into new systems
without modifying their original code.
Decorator
Decorator Method is structural design pattern, it allows to add behavior to individual objects, either
statically or dynamically, without affecting the behavior of other objects from the same class.
==================================================================================
==================================================================================
Database
SELECT emp_no, salary FROM salaries ORDER BY salary DESC LIMIT 1 OFFSET 1
--------------------------------------------------------------------------------------------------------------------------------------
IoC (Inversion of Control) is a fundamental principle in software design, particularly in the context of
frameworks like Spring. Here's an explanation of IoC:
Basic Concept:
Instead of the application controlling the flow of program logic, the framework takes control.
Key Aspects:
Idempotency – repeating req multiple times and each time will generate same results
Use limit handler to tracking spam req from same Ip – not active req – use rate limitors
API Gateway- instead of implementing Security at all places implement it at one place