Interview Notes
Interview Notes
Java
Core Concepts
• OOP Concepts:
o Encapsulation: The bundling of data and methods that operate on that data into
a single unit (a class). It hides the internal state of an object from the outside
world.
• Collections Framework:
o Set: A collection that does not allow duplicate elements. It models the
mathematical concept of a set. Common implementations: HashSet, TreeSet.
o Map: An object that maps keys to values. A Map cannot contain duplicate keys;
each key can map to at most one value. Common implementations: HashMap,
TreeMap, Hashtable.
• Java 8+ Features:
o Optional: A container object which may or may not contain a non-null value. It
helps in avoiding NullPointerExceptions.
o Functional Interfaces: An interface with exactly one abstract method. They are
a key component for using lambda expressions.
• Exception Handling:
• Multithreading:
o Deadlock: A situation where two or more threads are blocked forever, waiting for
each other to release a lock.
o Race Condition: A situation where multiple threads try to access and modify
the same shared data, and the outcome depends on the unpredictable order of
execution.
• JVM Internals:
o Heap vs Stack:
▪ Stack Memory: Stores local variables, method call frames, and primitive
data types. Each thread has its own private stack. It is faster than heap
memory.
▪ Heap Memory: Used for storing objects and their instance variables. It is
shared among all threads. Garbage collection operates on the heap.
Q&A: Java
• Nulls: HashMap allows one null key and multiple null values. Hashtable does not
allow any null keys or null values. If you try to insert one, it will throw a
NullPointerException.
• Inheritance: Hashtable is a legacy class and inherits from Dictionary, while HashMap is
part of the modern Java Collections Framework and inherits from AbstractMap.
o final variable: The value cannot be changed after it's initialized. It's a constant.
• finalize(): A method of the Object class. It is called by the Garbage Collector just before
an object is destroyed and its memory is reclaimed. Its use is generally discouraged due
to unpredictable behavior and performance issues. It's better to use try-with-resources
or the finally block for resource management.
JavaScript
Core Concepts
• ES6 Features: let/const (block scope), arrow functions (concise syntax, no this binding),
template literals (string interpolation), spread/rest operators, destructuring (unpacking
values from arrays/objects).
• this keyword: Refers to the context in which a function is executed. Its value depends
on how the function is called.
• Scope: The accessibility of variables, objects, and functions in different parts of your
code.
• == vs ===:
o == (loose equality): Checks for equality after type coercion. 1 == "1" is true.
o === (strict equality): Checks for equality without type coercion. Both the value
and the type must be the same. 1 === "1" is false.
Q&A: JavaScript
The Event Loop is a single-threaded loop that continuously checks the call stack and the
message queue.
• Call Stack: Where synchronous function calls are placed. When a function returns, it's
popped off the stack.
• Web APIs: Asynchronous operations like setTimeout, fetch, or DOM events are handled
by the browser's Web APIs.
• Message Queue (or Task Queue): Where the callbacks for asynchronous operations are
placed once the Web API has completed its task.
• The Loop: The Event Loop constantly checks if the call stack is empty. If it is, it takes
the first message from the message queue and pushes its corresponding callback onto
the call stack for execution. This non-blocking behavior is what allows JavaScript to
handle time-consuming operations without freezing the UI.
A closure is when a function remembers and can access its surrounding variables, even after
the outer function has finished executing.
Example:
JavaScript
function makeAdder(x) {
// 'x' is part of the closure
return function(y) {
return x + y;
};
[Link](addFive(2)); // Output: 7
[Link](addFive(10)); // Output: 15
In this example, makeAdder returns a new function. This new function "closes over" the variable
x from makeAdder's scope. Even though makeAdder has finished running, the addFive function
still has access to the value of x (which is 5). This is the closure in action.
C++
Core Concepts
• Memory Management:
o Stack: Memory allocated for local variables and function calls. It's managed
automatically and is very fast.
o Heap: Dynamic memory used for objects created with new. It must be managed
manually (with delete) or using smart pointers to avoid memory leaks.
o Smart Pointers: Objects that act like pointers but automatically manage
memory to prevent memory leaks. Examples: std::unique_ptr, std::shared_ptr.
• OOP:
o Abstract class: A class that cannot be instantiated on its own. It's designed to
be a base class for other classes, forcing them to implement the pure virtual
functions.
Q&A: C++
• Shallow Copy: Creates a new object, but instead of creating new copies of the
members (especially pointers or complex objects), it copies the memory addresses
(pointers) of the members from the original object. This means both the original and the
new object point to the same underlying data. If one object's data is modified, it will
affect the other.
• Deep Copy: Creates a new object and allocates new memory for all the members,
recursively copying the data from the original object. The new object is a completely
independent copy, and changes to one object's data will not affect the other. A deep
copy is essential when an object contains pointers or dynamically allocated memory.
SQL
Core Concepts
• Joins: INNER, LEFT, RIGHT, FULL joins combine rows from two or more tables based on
a related column. SELF join is a regular join that joins a table to itself.
• Indexes: Data structures that improve the speed of data retrieval operations on a
database table. They act like an index in a book.
• Common functions: COUNT (counts rows), GROUP BY (groups rows with the same
values), HAVING (filters groups created by GROUP BY), ROW_NUMBER() (assigns a
unique number to each row within a partition).
Q&A: SQL
Indexing improves performance by providing a fast way to look up data. Instead of scanning the
entire table (a "full table scan") to find a specific row, the database can use the index to quickly
jump to the data location.
• Faster reads: Queries with WHERE clauses, ORDER BY, and JOIN operations that use
indexed columns will execute much faster.
• Drawbacks: Indexes do add some overhead. They require additional storage space and
can slow down write operations (INSERT, UPDATE, DELETE), as the database needs to
update both the table data and the index itself.
Q: Difference between WHERE and HAVING.
• WHERE clause: Filters individual rows before they are grouped. It cannot use
aggregate functions like COUNT or SUM.
• HAVING clause: Filters groups of rows after they have been created by the GROUP BY
clause. It must be used with GROUP BY and can use aggregate functions.
Analogy:
• WHERE is like picking out specific ingredients from a shelf (e.g., "only get the red
apples").
• HAVING is like sorting those ingredients into different types and then filtering the groups
(e.g., "from all the fruit, only keep the groups that have more than 5 items").
Backend
Spring Boot
• Dependency Injection (DI): A design pattern where an object receives its dependencies
from an external source rather than creating them itself.
• IoC (Inversion of Control): A principle where the framework (Spring) manages the
objects' lifecycle and dependencies, rather than the application managing them. DI is a
form of IoC.
• Annotations:
• JPA/Hibernate: Spring Data JPA simplifies the implementation of data access layers.
@Entity maps a class to a database table, @Id defines the primary key, @OneToMany,
@ManyToMany define relationships.
These are all stereotype annotations that mark a class as a Spring Bean, but they serve
different semantic purposes and enable specific features.
• @Component: A generic stereotype for any Spring-managed component. It's the base
annotation for the other two.
• @Service: A specialized @Component used for classes in the service layer. It's
primarily for semantic clarity, indicating that the class holds business logic.
• @Repository: A specialized @Component used for classes in the data access layer. It
has a special feature: it enables the translation of persistence-related exceptions into
Spring's DataAccessException hierarchy, making error handling more consistent.
Hibernate / JPA
o Eager Loading: An associated object is loaded immediately along with the main
object. This can lead to performance issues if there are many associations.
o Native SQL: The standard SQL used by the underlying database. It's database-
dependent and can be useful for complex, non-portable queries.
Both methods are used to save an entity to the database, but they differ in their behavior and
state management.
• persist(): A JPA-specific method. It returns void. It saves a new entity to the database. If
the entity already exists, it will throw an exception. persist() requires a transaction
context and is the preferred method in modern JPA applications.
Key difference: persist() strictly follows the JPA specification and is used for new entities, while
save() is a more flexible (but less strict) Hibernate-specific method that can handle both new
and existing entities.
[Link] / Express
• Middleware: Functions that have access to the request object (req), the response
object (res), and the next middleware function in the application's request-response
cycle. They can modify req and res or end the cycle.
• RESTful APIs: A set of architectural principles for designing networked applications. It's
based on the use of HTTP methods to perform CRUD operations on resources.
• Principles:
o Statelessness: Each request from a client to the server must contain all the
information needed to understand the request.
• HTTP Methods: GET (retrieve), POST (create), PUT (update/replace), DELETE (delete),
PATCH (partial update).
• Status Codes: 200 (OK), 201 (Created), 400 (Bad Request), 401 (Unauthorized), 403
(Forbidden), 404 (Not Found), 500 (Internal Server Error).
1. Synchronous Communication (REST): One service calls another directly and waits for
a response. This is simple but can lead to tight coupling and cascading failures. A
common protocol is HTTP/REST.
• Monolithic: A single, self-contained unit where all components of the application (UI,
business logic, data access) are tightly coupled and packaged together. It's simpler to
develop initially and deploy, but scaling, maintenance, and adopting new technologies
can be challenging.
Frontend
React
• Props vs State:
o State: An object that holds data that may change over the lifetime of a
component. It's managed internally by the component.
o Reconciliation: The process by which React compares the new Virtual DOM
with the old one to identify the most efficient way to update the real DOM. This
"diffing" process makes React very fast.
Q&A: React
1. When a component's state or props change, React creates a new Virtual DOM tree for
the updated component.
2. It then compares this new tree with the previous Virtual DOM tree (the "diffing"
process).
4. Finally, it performs the updates directly on the real DOM, but only for the parts that have
actually changed. This is much faster than manipulating the entire real DOM tree.
HTML & CSS
• Semantic HTML: Using HTML tags that convey meaning and structure to the content,
like <article>, <section>, <header>, <footer>, etc. This improves accessibility and SEO.
• CSS Flexbox & Grid: Layout modules for creating flexible and responsive layouts.
• Media Queries: CSS rules that apply styles based on the device's characteristics (e.g.,
screen width, height, resolution). Essential for responsive design.
• Accessibility (A11y): Making websites usable by people with disabilities. alt text for
images and ARIA roles are crucial for screen readers.
• position: static;: The default position. The element follows the normal flow of the page.
Top, bottom, left, right properties have no effect.
• position: relative;: The element is positioned relative to its normal position. Using top,
bottom, left, right will move it from that original position, but its original space remains
in the document flow.
• position: absolute;: The element is removed from the normal document flow and
positioned relative to its closest positioned ancestor. If no positioned ancestor exists,
it's relative to the <html> element.
• position: fixed;: The element is removed from the normal document flow and
positioned relative to the viewport. It remains in the same position even when the page
is scrolled. Useful for fixed headers or footers.
• position: sticky;: A hybrid of relative and fixed. The element behaves like relative until a
certain scroll position is reached, at which point it "sticks" and behaves like fixed.
Tailwind CSS
• Boilerplate: Tailwind reduces the need to name classes and manage large CSS files.
• Customization: Tailwind is highly configurable, allowing you to define your own color
palettes, spacing scales, etc.
• Maintenance: Changes are localized to the HTML, making it easier to maintain and
refactor components without worrying about side effects.
Radix UI
Q&A: Radix UI
While you could build every UI component from scratch with just CSS and HTML, it would be
extremely time-consuming to ensure they are fully accessible (keyboard navigation, ARIA
attributes), maintain a consistent state (open/closed, disabled), and handle all the necessary
interactions.
• Logic and State: It manages the state and logic for complex components, freeing you
from writing that boilerplate code yourself.
• Styling Freedom: It's headless, meaning it doesn't impose any styling. You can use any
CSS method, including Tailwind CSS, to style the components exactly how you want.
This is a key advantage over pre-styled UI libraries like Bootstrap or Material UI.
Databases
• MySQL: A popular relational database management system (RDBMS) that stores data
in tables. It enforces a strict schema, supports transactions, and is widely used.
• MongoDB: A NoSQL database that stores data in flexible, JSON-like documents. It's
schema-less, making it suitable for applications with rapidly changing data
requirements.
• PostgreSQL: An advanced RDBMS known for its robust features, extensibility, and
compliance with SQL standards. It also offers advanced data types and JSONB support.
Q&A: Databases
• You need a flexible, dynamic schema. The data model can change over time without
requiring a rigid database migration. This is great for agile development.
• The data is hierarchical or document-oriented, where you can embed related data
within a single document (e.g., a blog post and its comments). This reduces the need for
complex joins.
• Data integrity and consistency are paramount. It is designed for applications that
require ACID properties.
AWS (Basics)
• EC2 (Elastic Compute Cloud): Provides resizable compute capacity in the cloud. It's
essentially a virtual server.
• S3 (Simple Storage Service): Object storage service that can be used to store and
retrieve any amount of data from anywhere on the web.
• RDS (Relational Database Service): Managed service for relational databases (MySQL,
PostgreSQL, etc.). It automates tasks like patching and backups.
• Lambda: A serverless compute service that runs your code in response to events and
automatically manages the underlying compute resources.
Q&A: AWS
Function-as-a-Service (FaaS)
Model Infrastructure-as-a-Service (IaaS)
/ Serverless
Feature EC2 (Elastic Compute Cloud) Lambda
Full control over the server (OS, runtime, No control over the underlying
Control
etc.). infrastructure.
Docker
Q&A: Docker
Highly portable, runs the same on Less portable due to the full
Portability
any OS with Docker. OS.
Feature Docker (Containerization) VM (Virtualization)
Kubernetes
• Pods: The smallest deployable unit in Kubernetes. A Pod contains one or more
containers.
• Deployments: Manages a set of identical Pods and ensures they are running.
• Services: An abstraction that defines a logical set of Pods and a policy by which to
access them.
Q&A: Kubernetes
• StatefulSet: Designed for stateful applications. It ensures that a fixed set of Pods is
running and provides a stable identity for each Pod (stable hostname, network ID, and
storage). This is crucial for databases, message queues, and other applications that
require persistent storage and ordered deployment/scaling.
Kafka
• Distributed messaging system: A platform for building real-time data pipelines and
streaming applications.
• Partition: Topics are divided into partitions, which are the fundamental unit of
parallelism.
Q&A: Kafka
• Messaging Model:
• Use Cases:
o Kafka: Best for data streaming, real-time analytics, and event sourcing. It's a
high-throughput, durable log.
Git
• git pull: Fetches changes from a remote repository and merges them into your current
branch.
• git stash: Temporarily shelves changes you don't want to commit yet.
Q&A: Git
• git merge: Combines the changes from two branches by creating a new merge commit.
This preserves the history of both branches and is generally safer and non-destructive.
Other Skills
Monitoring microservice logs is critical due to their distributed nature. The best approach is
centralized logging, using a solution like the ELK Stack.
2. Processing: Logstash processes these logs, parsing, enriching, and transforming them.
Agile / Scrum
o Roles: Product Owner (defines product backlog), Scrum Master (facilitates the
process), Development Team (builds the product).
• Agile: An iterative and incremental approach. The project is broken into small cycles
(sprints), and a working product is delivered at the end of each. It's flexible, and
requirements can change throughout the process.
• Responsive Web Design: An approach to web design that makes web pages render well
on a variety of devices and screen sizes.
1. Use a Mobile-first approach: Design for the smallest screen first and progressively
enhance the design for larger screens.
2. CSS Media Queries: Use @media rules to apply specific styles based on screen width,
allowing you to change layouts, font sizes, etc., for different devices.
3. Flexible Layouts: Use relative units like %, em, rem, vw/vh (viewport width/height)
instead of fixed units like px. Use CSS Flexbox and Grid for building flexible layouts that
adapt to screen size.
4. Flexible Images: Set images to max-width: 100%; to ensure they scale down within their
containers.