Handling Exceptions, Intro to Spring Data JPA Flashcards

1
Q

What annotation is used to create a centralized exception handler in Spring?

A

@ControllerAdvice is used to create a centralized exception handler in Spring.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How can you handle a specific exception within a controller in Spring Boot?

A

By using @ExceptionHandler within the controller for the specific exception type, you can handle exceptions at the controller level in Spring Boot.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What’s the purpose of @ExceptionHandler in Spring?

A

@ExceptionHandler is used to define methods that handle specific exceptions thrown by request handling methods in Spring controllers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the benefit of using centralized exception handling in Spring applications?

A

Centralized exception handling helps in separating exception handling logic from regular controller logic, making the code more organized and maintainable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you define a custom exception in Java for use in Spring applications?

A

You can create a custom exception by extending the RuntimeException class or its subclasses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In Spring Boot, what’s the recommended way to return custom error responses when an exception occurs?

A

Using ResponseEntity along with appropriate HTTP status codes and custom error messages is a recommended way to return custom error responses in Spring Boot.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is @ControllerAdvice used for in Spring?

A

@ControllerAdvice is an annotation used in Spring to define global elements to be used across multiple controllers. It primarily allows centralized handling of exceptions and applying global configurations to all or selected controllers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What types of concerns can be addressed using @ControllerAdvice in Spring?

A

@ControllerAdvice can handle various concerns such as exception handling, model attributes shared across multiple controllers, and applying response modifications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Can you specify the scope of controllers affected by @ControllerAdvice?

A

Yes, you can narrow down the scope by specifying the base packages or specific controllers using the basePackageClasses or basePackages attribute within @ControllerAdvice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Apart from handling exceptions, what other functionalities can @ControllerAdvice provide?

A

It can assist in manipulating the model attributes before they are added to the model by using @ModelAttribute annotated methods within @ControllerAdvice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does @ControllerAdvice relate to @ExceptionHandler?

A

@ExceptionHandler is one of the functionalities provided by @ControllerAdvice. It’s used to define methods that handle specific exceptions thrown by request handling methods in Spring controllers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is Object-Relational Mapping (ORM)?

A

ORM is a programming technique that facilitates the conversion of data between incompatible type systems—object-oriented programming languages and relational databases—by mapping objects to database tables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does ORM work?

A

ORM frameworks provide a layer of abstraction between the application and the database, enabling developers to interact with databases using object-oriented principles, where classes represent tables and instances represent rows.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the primary advantages of using ORM?

A

ORM simplifies database interactions by allowing developers to use programming language constructs instead of writing complex SQL queries, promotes code reusability, and abstracts database-specific implementation details.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are some popular ORM frameworks or libraries?

A

Examples of ORM frameworks include Hibernate (for Java), Entity Framework (for .NET), Django ORM (for Python), Sequelize (for Node.js), and SQLAlchemy (for Python).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What considerations should be taken into account while using ORM?

A

Proper understanding of the underlying SQL queries generated by ORM, performance implications, optimization techniques, and ensuring compatibility with the database schema are essential while using ORM in development.

17
Q

What is the purpose of JDBC?

A

JDBC facilitates the connection between Java applications and databases, providing a standard interface to execute SQL queries, retrieve results, and manage database transactions.

18
Q

How does JDBC work?

A

JDBC operates by using JDBC drivers to establish connections to the database, sending SQL queries, processing results, and handling transactions through a set of interfaces and classes provided by the JDBC API.

19
Q

What are the main components of JDBC?

A

JDBC consists of the DriverManager class for managing connections, the Connection interface for connecting to a database, the Statement and PreparedStatement interfaces for executing SQL queries, and the ResultSet interface for handling query results.

20
Q

What are some common operations performed using JDBC?

A

Common JDBC operations include establishing connections to databases, executing queries (INSERT, UPDATE, DELETE), retrieving query results, managing transactions, and handling exceptions related to database interactions.

21
Q

What is @ControllerAdvice in Spring MVC?

A

@ControllerAdvice is an annotation used in Spring MVC to define global exception handlers, centralized model attributes, and common behavior for multiple controllers.

22
Q

What is the purpose of @ControllerAdvice?

A

@ControllerAdvice allows centralized exception handling, enabling developers to define methods to handle exceptions across multiple controllers within an application.

23
Q

How is @ControllerAdvice used in Spring MVC?

A

Annotated classes with @ControllerAdvice contain methods annotated with @ExceptionHandler to handle specific exceptions thrown by controller methods.

24
Q

What types of operations can be performed using @ControllerAdvice?

A

With @ControllerAdvice, developers can define exception handling methods (@ExceptionHandler), add model attributes to all controllers (@ModelAttribute), and more.

25
Q

What is the benefit of using @ControllerAdvice?

A

@ControllerAdvice promotes code reuse, simplifies exception handling, centralizes error responses, and allows developers to encapsulate common logic across multiple controllers.

26
Q

What is Spring Data JPA?

A

Spring Data JPA is a part of the Spring Data project that simplifies data access by providing a higher-level abstraction over JPA (Java Persistence API) to work with relational databases using the Java Persistence API.

27
Q

What is the purpose of Spring Data JPA?

A

Spring Data JPA reduces boilerplate code by providing a set of abstractions and interfaces to interact with databases, allowing developers to perform CRUD (Create, Read, Update, Delete) operations and execute queries more efficiently.

28
Q

How does Spring Data JPA simplify database operations?

A

Spring Data JPA provides repository interfaces with predefined methods, eliminating the need for manual implementation of CRUD operations and allowing developers to focus on defining query methods or custom queries.

29
Q

What features does Spring Data JPA offer?

A

Spring Data JPA offers features like query creation from method names, custom query methods using @Query annotation, support for pagination, auditing, and automatic query execution based on method names.

30
Q

How does Spring Data JPA integrate with JPA implementations like Hibernate?

A

Spring Data JPA integrates seamlessly with JPA providers like Hibernate by providing implementations for repository interfaces, allowing developers to leverage JPA features without writing boilerplate code.

31
Q

What is ORM (Object-Relational Mapping)?

A

ORM is a programming technique used to facilitate the conversion between incompatible type systems: object-oriented programming languages and relational databases, mapping objects to database tables.

32
Q

How does ORM work?

A

ORM frameworks provide a layer of abstraction between the application and the database, enabling developers to interact with databases using object-oriented principles. Classes represent tables, instances represent rows, and relationships are mapped accordingly.

33
Q

What are the advantages of using ORM?

A

ORM simplifies database interactions, reduces the need for writing complex SQL queries, promotes code reusability, abstracts database-specific details, and facilitates rapid application development.

34
Q

What are some popular ORM frameworks?

A

Examples of ORM frameworks include Hibernate (for Java), Entity Framework (for .NET), Django ORM (for Python), Sequelize (for Node.js), and SQLAlchemy (for Python).

35
Q

What considerations are important when using ORM?

A

Understanding generated SQL queries, optimizing performance, managing relationships, handling database schema changes, and ensuring proper configuration are essential considerations while using ORM frameworks.

36
Q

What are the main differences between Hibernate and Spring Data JPA?

A

Hibernate is a full-fledged ORM framework with extensive features and configurations, while Spring Data JPA is a part of the Spring ecosystem that offers additional abstractions and simplifications for JPA-based data access in a Spring application context.

37
Q

How do Hibernate and Spring Data JPA relate to ORM?

A

Hibernate is a specific implementation of ORM for Java, providing comprehensive ORM features. Spring Data JPA, on the other hand, simplifies data access by building on top of JPA and providing additional abstraction and features.

38
Q
A