➢ JDBC: Java Database Connectivity
JDBC (Java Database Connectivity) is an API that allows Java applications to connect and interact with
databases (like MySQL, Oracle).
Why JDBC?
• To execute SQL queries from Java
• To insert, update, delete, and fetch data
• To make Java applications database-independent
Types of JDBC Drivers
1. Type 1 – JDBC-ODBC Bridge (Deprecated)
2. Type 2 – Native API Driver
3. Type 3 – Network Protocol Driver
4. Type 4 – Thin Driver (Most Used)
5. Type 4 driver is preferred because it is pure Java and platform-independent.
➢ Steps to Connect Java with Database (Very Important)
Load Driver
Create Connection
Create Statement
Execute Query
Process Result
Close Connection
❖ What is a Servlet?
❖ A Servlet is a server-side Java component used to handle client requests and generate
dynamic web responses.
Why Servlets?
• To build dynamic web applications
• Platform independent
• Better performance than JSP (logic-based)
• Secure & scalable
Servlet Lifecycle (Very Important )
load servlet class
init() – called once
service() – called for each request
destroy() – called once before removal
Types of Servlets
• GenericServlet
• HttpServlet (Most used)
Servlet Configuration
• Using [Link]
• Using @WebServlet annotation
Session Tracking in Servlet
• Cookies
• HttpSession
• URL Rewriting
• Hidden Form Fields
❖ JSP (JavaServer Pages)?
JSP (JavaServer Pages) is a server-side technology used to create dynamic web pages using
HTML with embedded Java code.
Internally JSP is converted into a Servlet
JSP Lifecycle (Important )
Translation (JSP → Servlet)
Compilation
Class Loading
jspInit()
_jspService()
jspDestroy()
❖ JSP vs Servlet:
JSP Servlet
UI based Logic based
HTML + Java Pure Java
Hard to
Easy to maintain
maintain
❖ What is JavaBeans?
JavaBeans is a reusable Java class that follows certain conventions and is mainly used to
encapsulate data.
Rules of JavaBeans (Very Important )
A JavaBean must:
Have private variables
Provide public getters and setters
Have a public no-argument constructor
Implement Serializable (recommended)
❖ Heap Memory?
Heap memory is used to store objects and instance variables.
Real-Life Example
Heap = Common store room
All employees can access stored items.
❖ Stack Memory?
Stack memory is used to store method calls, local variables, and references.
Each thread has its own stack.
Real-Life Example
Stack = Personal notebook
Each person has their own notebook.
❖ Garbage Collection (GC)?
Garbage Collection is the process of automatically removing unused objects from heap
memory.
Objects created in heap
Objects without reference become eligible for GC
GC frees memory
Types of Garbage Collectors
• Serial GC
• Parallel GC
• CMS
• G1 GC (Most used)
❖ What is Connection Pooling?
Connection Pooling means reusing database connections instead of creating a new one
every time.
Real-Life Example
Connection Pool = Parking lot
Cars (connections) are reused instead of buying new cars every time.
❖ What is Singleton?
A Singleton class allows only one object to be created in the entire application.
❖ What is Immutable?
An immutable class is a class whose object values cannot be changed after creation.
❖ SOLID Principles:
Principle Meaning
S Single Responsibility
O Open/Closed
L Liskov Substitution
I Interface Segregation
D Dependency Inversion
❖ Factory Design Pattern?
Factory pattern provides object creation without exposing instantiation logic.
❖ What is Maven?
Maven is a build automation and dependency management tool for Java projects.
[Link]
Dependencies
Build lifecycle
Repositories
❖ Reflection API?
Reflection API is used to inspect and manipulate classes at runtime.
Uses
• Frameworks (Spring, Hibernate)
• Dynamic object creation
• Method invocation
❖ SPRING FRAMEWORK:-
Q1. What is Spring Framework?
Spring Framework is a Java framework used to build enterprise applications.
It helps in:
• Reducing code
• Managing objects automatically
• Making applications loosely coupled
•
Q2. Why do we use Spring?
• Provides Dependency Injection
• Makes code easy to test
• Supports MVC, Security, REST, Microservices
• Reduces boilerplate code
Q3. What are the main modules of Spring?
• Spring Core
• Spring MVC
• Spring AOP
• Spring ORM
• Spring Security
• Spring Boot
Q4. What is IOC in Spring?
IOC (Inversion of Control) means Spring controls object creation, not the developer.
Instead of new keyword, Spring creates and manages objects.
Dependency Injection (DI)
Q5. What is Dependency Injection?
Dependency Injection means providing required objects to a class from outside, instead of
creating them inside the class.
Q6. Types of Dependency Injection?
1. Constructor Injection (most recommended)
2. Setter Injection
3. Field Injection
Q7. Why is DI important?
• Loose coupling
• Easy testing
• Easy maintenance
• Better code readability
Q8. What is a Bean in Spring?
A Bean is an object managed by Spring container.
Q9. What is ApplicationContext?
ApplicationContext is the Spring container that:
• Creates beans
• Manages lifecycle
• Injects dependencies
Q10. Difference between BeanFactory and ApplicationContext?
BeanFactory ApplicationContext
Lazy loading Eager loading
BeanFactory ApplicationContext
Basic features Advanced features
Older Most used
Spring MVC
Q11. What is Spring MVC?
Spring MVC is used to build web applications using Model-View-Controller design
pattern.
Q12. What is MVC?
• Model → Data
• View → UI (HTML, JSP)
• Controller → Handles requests
Q13. Flow of Spring MVC?
1. Request comes to DispatcherServlet
2. DispatcherServlet sends to Controller
3. Controller returns Model + View
4. View is rendered to user
Q14. What is DispatcherServlet?
DispatcherServlet is the front controller of Spring MVC.
Q15. Common Spring MVC annotations?
• @Controller
• @RequestMapping
• @GetMapping
• @PostMapping
• @PathVariable
• @RequestParam
Spring Boot
Q16. What is Spring Boot?
Spring Boot is built on top of Spring to simplify application development.
Q17. Advantages of Spring Boot?
• No XML configuration
• Auto configuration
• Embedded server (Tomcat)
• Faster development
Q18. What is @SpringBootApplication?
It is a combination of:
• @Configuration
• @EnableAutoConfiguration
• @ComponentScan
Q19. Difference between Spring and Spring Boot?
Spring Spring Boot
Manual configuration Auto configuration
XML required No XML
External server Embedded server
Q20. What is embedded server?
Spring Boot includes Tomcat/Jetty, so no need to deploy WAR file manually.
REST API Basics
Q21. What is REST?
REST is an architecture style for building web services using HTTP.
Q22. What is REST API?
A REST API allows client and server communication using HTTP methods.
Q23. HTTP Methods?
Method Purpose
GET Fetch data
POST Create data
PUT Update data
DELETE Delete data
Q24. What is @RestController?
@RestController returns JSON response, not views.
Q25. Difference between @Controller and @RestController?
@Controller @RestController
Returns View Returns JSON
MVC apps REST APIs
Q26. What is @RequestBody?
Used to read JSON data from request body.
Q27. What is @ResponseBody?
Converts Java object into JSON response.
Q28. What is HTTP Status Code?
Indicates result of request.
Examples:
• 200 → OK
• 201 → Created
• 400 → Bad Request
• 404 → Not Found
• 500 → Server Error
Modern Architecture – Microservices
Q29. What is Microservices Architecture?
Microservices means breaking one large application into small independent
services.
Q30. Advantages of Microservices?
• Independent deployment
• Scalability
• Fault isolation
• Technology flexibility
Q31. Difference between Monolithic and Microservices?
Monolithic Microservices
Single application Multiple services
Hard to scale Easy to scale
One failure affects all Independent failures
Q32. Communication between Microservices?
• REST API
• Feign Client
• Message Queue (Kafka/RabbitMQ)
Q33. What is API Gateway?
API Gateway acts as single entry point for all microservices.
Q34. What is Service Discovery?
Helps services find each other automatically.
Example:
• Eureka Server
Q35. What is Config Server?
Central place to manage configuration files for all microservices.