100000380
Points
Questions
185
Answers
186
-
Auto wiring is a capability by which Spring container is able to establish relationships between collaborating beans without the need to provide explicit wiring instructions through <constructor-arg> and <property> elements on bean definition (XML) files.
This helps in reducing the amount of XML configurations. The auto wiring functionality has five modes:
• no – This is the default setting which means no auto wiring. Explicit bean reference should be provided through the XML file.
• byName – Auto wiring by property name. When this option is used, the container attempts to look for a bean that has the same name as the property of the auto wired bean.
• byType – Auto wiring by property type. The container attempts to match all properties of the auto wired bean with beans whose types are compatible to the properties.
• constructor – This is similar to byType but applies to constructor. The container attempts to match up a constructor of the auto wired bean with beans whose types are assignable to the constructor arguments
• autodetect – The container attempts to apply ‘Auto wiring by Constructor’ first if it fails, it applies ‘Auto wiring byType’.
This answer accepted by JavaNinja. on 17th September 2018 Earned 15 points.
- 1346 views
- 1 answers
- 0 votes
-
Bean life cycle in Spring BeanFactory Container is as follows:
a) The spring container finds the bean’s definition (from the XML file) and instantiates the bean.
b) The bean is populated with all the properties as specified in the bean definition. If a property is reference to another bean, then the other bean will be created and populated, and reference injected into the bean.
c) If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean’s ID.
d) If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of Bean Factory.
e) If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization() methods will be called for pre initialization.
f) If an init-method is specified for the bean, it will be called.
g) If there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() methods will be called.
This answer accepted by JavaNinja. on 17th September 2018 Earned 15 points.
- 1262 views
- 1 answers
- 0 votes
-
A BeanFactory is a factory class that holds bean definitions and then instantiates the beans whenever asked for by clients. It also creates dependencies between collaborating objects as they are instantiated. BeanFactory also enforces the life cycle of a bean, making calls to various initialization and destruction methods.
ApplicationContext is a more advanced container for beans. It provides all the BeanFactory functions like loading bean definitions, wiring beans together, and providing beans upon request. It also provides the following additional functions:
• A means for resolving text messages, including support for internationalization.
• A generic way to load file resources.
• Events to beans that are registered as listeners.ApplicationContext is the preferred way to access beans in Spring.
This answer accepted by JavaNinja. on 17th September 2018 Earned 15 points.
- 1449 views
- 1 answers
- 0 votes
-
Spring framework supports two types of Dependency Injection
• Constructor Injection – Dependencies are provided by constructor parameters
• Setter Injection – Dependencies are assigned through setter methods (Java Beans properties) after object instantiation using a no argument constructorThis answer accepted by JavaNinja. on 17th September 2018 Earned 15 points.
- 2958 views
- 1 answers
- 0 votes
-
Software components (Client), are often a part of a set of collaborating components which depend upon other components (Services) to successfully complete a business function. The client object need to know which service objects to communicate with, where to locate them and how to communicate with them.
Dependency Injection is based on the principle of ‘Inversion of Control’. The idea is to avoid direct dependency between collaborating objects by not creating objects using ‘new’ operator. Dependency injection is a way of structuring code such that clients do not locate or instantiate services as part of usual logic. Rather the dependencies are provided in a configuration file / through annotations and an external component (in case of spring framework the IoC container) is responsible for hooking up the objects.
One of the biggest advantages of dependency injection is that it reduces coupling between objects thereby making testing a lot easier. Independent clients are easier to unit test in isolation using stub or mock objects.
This answer accepted by JavaNinja. on 17th September 2018 Earned 15 points.
- 1260 views
- 1 answers
- 0 votes
-
In Java, Stack is a collection of objects that works in LIFO (Last in First out) mechanism while Queue is FIFO (First in First out).
This means that the object that is inserted first is removed last in a stack while an object that is inserted first is removed first in a queue.
Note:- Stack is deprecated and is recommended to use Deque instead.
This answer accepted by JavaNinja. on 17th September 2018 Earned 15 points.
- 2898 views
- 1 answers
- 0 votes
-
In Java, shallow copy is a bit-wise copy of an object. A new object is created that has an exact copy of the values in the original object. If any of the fields of the object are references to other objects, just the reference addresses are copied i.e., only the memory address is copied. The default implementation of clone() method in Java performs a shallow copy.
A deep copy copies all fields, and makes copies of dynamically allocated memory pointed to by the fields. A deep copy occurs when an object is copied along with the objects to which it refers.
This answer accepted by JavaNinja. on 17th September 2018 Earned 15 points.
- 1303 views
- 1 answers
- 0 votes
-
A variable can be made non-serializable by declaring it as transient by using ‘transient’ keyword. By default all variables are persistent.
Variables can be marked ‘transient’ when you want to avoid persisting them, you don’t have the necessity to maintain their state.This answer accepted by JavaNinja. on 17th September 2018 Earned 15 points.
- 1196 views
- 1 answers
- 0 votes
-
Serialization is the process of making the object’s state persistent. The state of an object is converted into stream of bytes. Serialization of an object can be achieved by implementing java.io.Serializable interface which is a marker interface.
Serialization is one of the important concepts in Java which is used when an object needs to be stored into a file or transmitted through a network or written to some persistent storage mechanism.
This answer accepted by JavaNinja. on 17th September 2018 Earned 15 points.
- 1237 views
- 1 answers
- 0 votes
-
• Main difference between wait() and sleep() is that wait() method release the ownership of the acquired monitor when thread is waiting while Thread.sleep() method keeps the lock or monitor even if thread is waiting.
• The wait() method should be called from synchronized block while there is no such requirement for sleep() method.
• Another difference is Thread.sleep() method is a static method and applies on current thread, while wait() is an instance specific method and wakes up only if some other thread calls notify() method on same object.
• In sleep() method, sleeping thread immediately goes to Runnable state after waking up (after the time elapses) while in case of wait(), waiting thread first acquires the lock and then goes into Runnable state.
This answer accepted by JavaNinja. on 17th September 2018 Earned 15 points.
- 1652 views
- 1 answers
- 0 votes