Spring Cloud Test 1 — Questions and Answers
Question 1: In transactional management, what is ACID?
- Accurate, Controlled, Independent, Done
- Atomicity, Consistency, Isolation, Durability (Correct answer)
- Accurate, Controlled, Isolation, Durability
- Atomicity, Consistency, Independent, Done
Correct answer: Atomicity, Consistency, Isolation, Durability
ACID is an acronym that stands for Atomicity, Consistency, Isolation, and Durability, which are a set of properties guaranteeing that database transactions are processed reliably. Atomicity ensures that a transaction is treated as a single, indivisible unit; Consistency ensures that a transaction brings the database from one valid state to another; Isolation ensures that concurrent transactions do not interfere with each other; and Durability ensures that once a transaction is committed, its changes are permanent.
Question 2: What exactly is the Spring MVC framework?
- Spring MVC framework is used for Transaction management for WEb Applications
- Spring MVC framework is used for AOP for Web Applications
- The Spring web MVC framework provides model-view-controller architecture and ready components that can be used to develop flexible and loosely coupled web applications. (Correct answer)
- Spring MVC framework is Model-Value-Class architecture and used to bind model data with values
Correct answer: The Spring web MVC framework provides model-view-controller architecture and ready components that can be used to develop flexible and loosely coupled web applications.
The Spring Web MVC (Model-View-Controller) framework is a robust and flexible architecture designed for developing web applications in Java. It provides a clear separation of concerns by dividing an application into three interconnected components: the Model (data), the View (user interface), and the Controller (request handling). This architecture promotes loose coupling, making applications easier to develop, test, and maintain.
Question 3: What exactly is spring?
- Spring is a proprietary framework
- Spring is an open source development framework for enterprise Java. (Correct answer)
- Spring is a development framework for PHP based applications
- Spring is a development framework for .NET applications
Correct answer: Spring is an open source development framework for enterprise Java.
Spring is an open-source, comprehensive application development framework for enterprise Java. It provides extensive infrastructure support for developing robust Java applications, simplifying common tasks like dependency injection, aspect-oriented programming, and data access. Spring's modular design allows developers to use only the parts of the framework they need, making it highly versatile and widely adopted.
Question 4: If a bean is scoped to an HTTP session, it is considered scoped.
- request
- prototype
- global-session
- session (Correct answer)
Correct answer: session
In Spring, when a bean is scoped to an HTTP session, it means that a single instance of that bean is created for each user's HTTP session. This 'session' scope ensures that the bean's state is maintained uniquely for a particular user throughout their interaction with the web application. Once the HTTP session ends, the bean instance is destroyed.
Question 5: What exactly is a target object?
- This is used to inject values in the object
- This is not invoked during program execution by the Spring AOP framework
- The object being advised by one or more aspects, this object will always be a proxy object, also referred to as the advised object. (Correct answer)
- A represents an object in your application where you can plug-in AOP aspect
Correct answer: The object being advised by one or more aspects, this object will always be a proxy object, also referred to as the advised object.
In Spring's Aspect-Oriented Programming (AOP), the 'target object' refers to the object that is being advised by one or more aspects. This is the actual business logic object on which the advice (e.g., logging, security) is applied. When AOP is used, the Spring framework typically creates a proxy object that wraps the target object, and it is this proxy that is injected into other components, also known as the advised object.
Question 6: Which version of the spring framework introduces thread scoped beans?
- 2.0
- 3.0 (Correct answer)
- 4.0
- 1.0
Correct answer: 3.0
Spring Framework version 3.0 introduced the concept of thread-scoped beans. This scope ensures that a single instance of a bean is created and managed for the lifetime of a single execution thread. This is particularly useful in multi-threaded environments where each thread requires its own isolated instance of a bean.
Question 7: What is autowriting autodetect mode?
- Auto-writing based on the name of the property. Spring tries to match and wire its properties to the beans in the configuration file that have the same name.
- ByType is similar to type, except that type applies to constructor arguments. A fatal error is raised if there isn't exactly one bean of the constructor argument type in the container.
- autowriting based on the type of property. If a property's type matches exactly one of the beans named in the configuration file, Spring will try to match and wire it.
- Spring tries to wire using autowire by constructor first, then autowire by byType if that doesn't work. (Correct answer)
Correct answer: Spring tries to wire using autowire by constructor first, then autowire by byType if that doesn't work.
The `autodetect` autowiring mode in Spring attempts to wire beans using a specific fallback mechanism. It first tries to autowire by constructor, meaning it looks for a constructor whose arguments can be satisfied by existing beans in the container. If that fails, it then attempts to autowire by `byType`, matching properties based on their data types. This provides a flexible approach to dependency injection.
Question 8: What exactly is an aspect?
- Aspect represents properties of spring based application
- Aspect is a way to do the dependency injection
- A module which has a set of APIs providing cross-cutting requirements (Correct answer)
- Aspect is used to log information of application
Correct answer: A module which has a set of APIs providing cross-cutting requirements
An aspect in Spring AOP (Aspect-Oriented Programming) is a modular unit that encapsulates a cross-cutting concern, such as logging, security, or transaction management. It provides a set of APIs to define and apply these concerns across multiple points in an application without modifying the core business logic. This approach helps in decoupling concerns, leading to cleaner, more modular, and maintainable code.
Question 9: What is the case with collection configuration components using the props tag?
- This can be used to inject a collection of name-value pairs where the name and value are both Strings.
- This helps in writing a list of values, allowing duplicates
- This helps in writing a list of values but without any duplicates
- This can be used to inject a collection of name-value pairs where name and value can be any type
In Spring's XML configuration, the `<props>` tag is specifically used to inject a `java.util.Properties` object into a bean. This Java utility class is designed to store a collection of name-value pairs, where both the name (key) and the value are always represented as Strings. It's ideal for injecting configuration properties that consist of simple string-based key-value mappings.
In transactional management, what is ACID?