Interview Questions:
What is polymorphism?
what is difference between abstract class and interface?
what is constructor overloading?
type of inheritance
type of access modifiers and specification
list all keywords provided by java
what is diamond problem in java
what is composition and aggregation
what is encapsulation
what is exception handling
what is inheritance
Collection Framework
<------------------------------------------------------------------------------------------------>
difference between String, string buffer and string builder
String Constant Pool
why abstraction is needed we have inheritance
what is runtime polymorphism internal working
what is functional interface
what is singleton class
difference between array-list and linked-list
concurrent modification exception
how to create build of an application from CMD
what is exception? and it'st types?
user defined exception
exception vs error
what is Exception propagation?
how do you create a custom exception in your project
can make class static?
Collection Frame Work (All)
what is IOC
JPA/JDBC
if you have number of fields to store into DB then how you can do?
in rabbit-MQ, how you are sending msg to queue?
web-client, Rest Template
What is micro-service?
Monolithic is Better at deployment then why micro-service
why you are using microservice when already monolithic is there?
how micro-service is helpful
can I use elastic-search as database? why it’s needed?
java versions and features
168.What is difference between new Arraylist and Arrays.asList
169.Which one is fast LinkedList or Arraylist?
170.Which case would you prefer LinkedList and which case Arraylist ?
171.Difference between Aggregation and composition
172.What is Fault tolerance
173.Jwt authentication related questions
174.Heap Memory and JVM
175.How do you create HTTP POST request in Java
176.What is the use of super keyword
177.What is throw, throws and when do we use these?
178.What is synchronization?
179.What is a tree set?
180.Explain the role of API Gateway in a microservices architecture?
181.Explain functional interface and what are some of the available interfaces?
182.What are REST API Best practices?
183.What is a one-to-one mapping and how to set up it with JPA/Hibernate?
184.Difference between entity object and value object?
185.What is the difference between ClassNotFoundException and NoClassDefFoundError
@Controller and @RestController
--------------------------------------------------------------------------------------------------------------------------------------
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.
2. Difference between comporater and comparable.
3. Difference beteween finialized method and finily keyword.
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.
6. Difference between classloader.getresource and class.getresource.
7. Difference between classloader and class.forName.
8. Scenerio where String builder is preferable over the String buffer.
9. Java memory model.
10. Generational Gurbage collection.
11. What make an object immutable, scenerio where using immutable object would be
advantage over the mutable.
12. What is java Serialization. Secialization Attacks.
13. Composition over inheritance principal.
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.
17. Explain the spring bean lifecycle.
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: -
JVM memory areas- Stack, heap, method area
Multitenancy
DDL (Data Definition language) – Create, Alter, Drop, Truncate, Rename
DML (Data Manipulation Language)- Select, Insert, Update, Delete
Indexing in DB table its advantages and disadvantages
AOP - > Aspect Oriented Programming
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
- Single Responsibility Principle (SRP)
- Open-Closed Principle (OCP)
- Liskovs Substitution Principle (LSP)
- Interface Segregation Principle (ISP)
- Dependency Inversion Principle (DIP)
Exception Handling IN AOP:
@RestControllerAdvice
public class WebRestControllerAdvice {
@ExceptionHandler (CustomNotFoundException.class)
public ResponseMsg handleNotFoundException(CustomNotFoundException ex) {
return new ResponseMsg(ex.getMessage());
}
}
----------------------------------------------------------------------------------------------------------------
Microservice Design Pattern:
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 a choreography-based system, services run independently and asynchronously. Each
service listens for specific events and reacts to them without requiring direct interaction
with other services. This means that services operate concurrently but not necessarily
simultaneously, as they respond to events at their own pace.
How Choreography Works
1. Event-Driven Architecture: Services communicate through events. One service
publishes an event, and other services that are interested in that event respond to it.
2. Loose Coupling: Services are loosely coupled, meaning they do not need to know
about each other directly. They only need to understand the events they produce
and consume.
3. Asynchronous Communication: Services process events asynchronously. When a
service publishes an event, it does not wait for other services to respond. Each
service processes the event when it receives it.
Example Scenario: E-commerce Order Processing
In an e-commerce system, when a customer places an order, the following services might be
involved:
1. Order Service: Publishes an "Order Placed" event.
2. Inventory Service: Listens for the "Order Placed" event and updates inventory.
3. Payment Service: Listens for the "Order Placed" event and processes payment.
4. Shipping Service: Listens for the "Order Placed" event and schedules shipment.
5. Notification Service: Listens for the "Order Placed" event and sends a confirmation
email.
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.
How Orchestration Works
1. Central Coordinator: A central orchestrator manages the workflow, calling each
service in the required sequence.
2. Direct Commands: The orchestrator directly invokes services and waits for their
responses, handling success and failure scenarios.
3. Synchronous Communication: Services typically communicate synchronously with
the orchestrator, though the orchestrator may use asynchronous calls depending on
the system design.
4. Compensation: In case of a failure, the orchestrator triggers compensating
transactions to undo previous steps.
Example Scenario: Travel Booking System
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
Steps to Implement the Strangler Pattern
1. Identify the Functionality to Replace:
o Break down the old system into smaller parts or functionalities.
o Prioritize which parts need to be modernized first.
2. Build the New System in Parallel:
o Develop new components or services that replicate the functionality of the old
system.
o These new components run alongside the old system without disrupting it.
3. Redirect Traffic to the New System:
o Gradually shift user interactions and data processing from the old system to the new
one.
o This can be done using techniques like proxying, routing, or feature toggles.
4. Retire the Old System:
o Once all functionalities have been successfully moved to the new system, the old
system can be retired.
o This step ensures that there is no sudden disruption to users or business processes.
Advantages of the Strangler Pattern
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.
Key Takeaways for an Interview
What: The Strangler Pattern is a strategy for gradually replacing an old system with a new
one.
How: It involves identifying parts of the old system to replace, building new components in
parallel, redirecting traffic, and retiring the old system incrementally.
Why: This pattern reduces risk, allows for continuous improvement, and provides a smooth
transition for users.
API apart from rest
1 GraphQL:
Query language for APIs
Allows clients to request specific data structures
Single endpoint for all operations
Strongly typed schema
Reduces over-fetching and under-fetching of data
2 WebSocket:
Full-duplex, bidirectional communication
Persistent connection over a single TCP socket
Reduced latency compared to HTTP polling
Ideal for real-time applications
3 SOAP:
XML-based messaging protocol
Platform and language independent
Supports WS-Security for enterprise-grade security
Uses WSDL for service description
4 MQTT:
Publish-subscribe messaging protocol
Designed for high-latency or unreliable networks
Quality of Service (QoS) levels for message delivery
Ideal for IoT and mobile applications
--------------------------------------------------------------------------------------------------------------------------------------
Design patterns in java
---------------------------------
Creational
Singleton
Factory
Interface Shape {
void getname();
public class circle implements shape
public void getname()
sysout("circle");
public class Squre implements shape
public void getname()
sysout("Squre");
public class triangle implements shape
public void getname()
sysout("Triangle");
public class factory()
public shape getInstance(String name)
{
if(name.equals("circle"))
return new circle();
if(name.equals("squar"))
{return new square();}
if(name.equals("triangle"))
return new triangle();
main()
factory f = new factory();
Shape sh1 = f.getinstance("triangle");
s1.getname();
Builder –
@builder
Don't want all the parameters
need to remember the seq. of the parameter
---------------------------------
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.
Iterator - to get objects sequentially
------------------------------------
Adapter
Integration of Existing Code:
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
Group By ----> (for aggregation with name) I need to remember
Ex. Get count of employee by department name
SQL for highest second salary
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:
IoC inverts the flow of control compared to traditional programming.
Instead of the application controlling the flow of program logic, the framework takes control.
Key Aspects:
Dependency Injection (DI):
A form of IoC where dependencies are "injected" into objects.
Objects don't create or manage their dependencies; they're provided externally.
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
Java 8 changes in HashMap
Why default was introduced in interface
API Gateway- instead of implementing Security at all places implement it at one place
Spring cloud config server