0% found this document useful (0 votes)
5 views3 pages

Java 005

The document provides an overview of the Spring Framework (version 3.x), detailing its architecture, key components, and modules such as Dependency Injection, Spring AOP, and Hibernate. It explains concepts like Spring Beans, their lifecycle, autowiring, and various bean scopes, as well as Hibernate's ORM principles and caching mechanisms. Additionally, it covers the implementation of RESTful services and the use of annotations in both Spring and Hibernate for managing data and relationships.

Uploaded by

d7frpg49wb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Java 005

The document provides an overview of the Spring Framework (version 3.x), detailing its architecture, key components, and modules such as Dependency Injection, Spring AOP, and Hibernate. It explains concepts like Spring Beans, their lifecycle, autowiring, and various bean scopes, as well as Hibernate's ORM principles and caching mechanisms. Additionally, it covers the implementation of RESTful services and the use of annotations in both Spring and Hibernate for managing data and relationships.

Uploaded by

d7frpg49wb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Spring Framework (version 3.

x)

I. Introduction to Spring

1. What is Spring?
Spring is an open-source framework used for building enterprise applications in Java. It provides comprehensive infr
tures like Dependency Injection (DI), Aspect-Oriented Programming (AOP), and transaction management.

2. Spring Architecture explanation and all its components?


Spring's architecture is based on several key components:
Core Container: Contains core functionalities, including beans, AOP, and context.
Spring BeanFactory: Responsible for the creation and management of beans.
Spring ApplicationContext: Provides more advanced features like internationalization and event propagation.
Spring AOP: Supports Aspect-Oriented Programming.
Spring Data Access/Integration: Manages JDBC, ORM frameworks (like Hibernate), and transactions.
Spring MVC: Web framework for building web applications.
Spring Security: Provides security features such as authentication and authorization.

3. Introduction to all modules of Spring


Spring Bean Factory: A container for creating and managing beans.
Spring Application Context: An advanced container that provides enterprise features.
Spring Dependency Injection (DI): Mechanism where dependencies are injected into classes rather than being create

II. Dependency Injection

1. What is Dependency Injection?


Dependency Injection (DI) is a design pattern where an object’s dependencies are injected by an external entity (like
lf.

2. How is it implemented using Spring Framework?


Spring implements DI by using either constructor injection or setter injection to provide dependencies to beans at ru

3. Bean Wiring mechanisms in Spring -


XML-based wiring: Beans and their dependencies are configured in XML files.
Annotation-based wiring: Using annotations like @Autowired and @Component.
Java-based wiring: Using @Configuration classes and @Bean methods.

4. What is Spring Bean and explain life cycle?


A Spring Bean is an object that is instantiated, configured, and managed by the Spring IoC container. The lifecycle inc
Instantiation
Dependency injection
Initialization (via @PostConstruct or init-method)
Destruction (via @PreDestroy or destroy-method)

5. Bean Scopes -
Singleton: Only one instance of the bean is created.
Prototype: A new instance is created every time it is requested.
Request: A new instance is created for each HTTP request (used in web applications).
Session: A new instance is created for each HTTP session.
Global Session: A new instance for each global HTTP session.

6. What is Autowiring?
Autowiring is a feature that allows Spring to automatically inject dependencies into beans without needing to specify

7. What is Bean wiring and @Autowired annotation?


Bean wiring refers to the configuration of beans and their dependencies. The @Autowired annotation is used for aut
to a bean.
8. What are different types of Spring Bean autowiring?
By Type (@Autowired): Spring injects dependencies by matching the type.
By Name (@Autowired + @Qualifier): Spring injects dependencies by matching the bean name.
Constructor-based Autowiring: Spring injects dependencies via constructor.
Autowiring by Constructor is used when constructor injection is preferred.

9. What is DispatcherServlet and ContextLoaderListener?


DispatcherServlet: Central dispatcher for HTTP requests in Spring MVC. It dispatches requests to appropriate handle
ContextLoaderListener: Initializes the Spring context (application context) when the web application starts.

10. What is ViewResolver in Spring?


ViewResolver is a Spring MVC component that resolves logical view names to actual views (such as JSPs or HTML).

11. How can we use Spring to create Restful Web Service returning JSON response?
You can use @RestController and @RequestMapping annotations to create RESTful web services that return JSON re
t.
@Component, @Service, @Repository

12. These are specializations of the @Component annotation in Spring:


@Component: Generic stereotype for any Spring-managed bean.
@Service: Indicates that a class performs service tasks (business logic).
@Repository: Indicates that a class is a Data Access Object (DAO) and interacts with the database.

III. Spring AOP

13. What is Spring AOP?


Spring AOP (Aspect-Oriented Programming) is a framework that allows separation of concerns by applying cross-cutt
f an application.

14. Implementation of Spring AOP?


You implement AOP in Spring by defining aspects (classes with advice), applying them using @Aspect, and creating p

15. What is Aspect, Advice, Pointcut, JointPoint, and Advice Arguments in AOP?
Aspect: A module that contains cross-cutting concerns.
Advice: Code that is executed when a pointcut expression matches a method execution.
Pointcut: Expression that defines where advice should be applied (methods).
JointPoint: A point in the program execution where an aspect can be applied (usually method executions).
Advice Arguments: Parameters passed to advice methods that allow them to work with the targeted methods.

16. Compile time weaving vs load time weaving?


Compile time weaving: AOP aspects are woven at compile-time.
Load time weaving: AOP aspects are woven when the class is loaded into the JVM.

IV. Hibernate Framework (version 3.x)

17. Why Hibernate?


Hibernate provides a solution for persistent data management by mapping Java objects to database tables. It elimina
bases.

18. What is ORM principle?


Object-Relational Mapping (ORM) is the concept of mapping an object-oriented domain model to a relational databa

19. Why ORM?


ORM simplifies data manipulation by abstracting the complexities of raw JDBC and SQL, offering better maintainabili
ORM implementations
Hibernate
JPA (Java Persistence API)
MyBatis
20. Which all Hibernate annotations used? Explain
@Entity: Marks a class as an entity to be mapped to a database table.
@Table: Specifies the table name for the entity.
@Id: Marks the primary key field.
@GeneratedValue: Specifies how the primary key is generated.
@Column: Maps a field to a column in the database.
@OneToMany, @ManyToOne, @ManyToMany: Define relationships between entities.
@JoinColumn: Specifies the foreign key column for relationships.

21. Hibernate SessionFactory, Session, Is Session thread-safe?


SessionFactory: A factory for creating Hibernate Sessions. It is thread-safe and should be created once.
Session: A single-threaded unit of work in Hibernate, used to interact with the database. It is not thread-safe and sho
Hibernate Cache -
First-Level Cache: Default session cache, scoped to the current session.
Second-Level Cache: A session factory-wide cache.

22. How to configure second-level cache?


You can enable the second-level cache by configuring it in the hibernate.cfg.xml or persistence.xml file and specifyin

23. What is Query Cache in Hibernate?


Query cache stores the results of queries for reuse, improving performance by reducing repeated database hits for t

24. Mapping Collections and Associations

To define sets, maps, lists in Hibernate


Set: Use @ElementCollection or @OneToMany for one-to-many relationships.
Map: Use @OneToMany with @MapKey to define a map relationship.
List: Use @OneToMany with @OrderColumn to maintain order.

Association Mappings:
One-to-One: Use @OneToOne annotation to define a one-to-one relationship.
One-to-Many: Use @OneToMany annotation to define a one-to-many relationship.
Many-to-One: Use @ManyToOne annotation to define a many-to-one relationship.
Many-to-Many: Use @ManyToMany annotation to define a many-to-many relationship.

V. Hibernate Caching

25. What is caching?


Caching stores frequently accessed data to reduce database load and improve performance.

26. Types of caching in Hibernate?


First-level cache: Automatic and scoped to a session.
Second-level cache: Optional and scoped to the session factory.
Query cache: Stores query results.

27. Using Hibernate Annotations (if time permits)


Hibernate annotations are used to map Java classes to database tables and define relationships. Common annotatio

You might also like