Search Interview Questions
| 3193 questions in repository.|
There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Have a video suggestion.
Click Correct / Improve and please let us know.
|Java - Interview Questions and Answers|
|Ans. 1. In Setter Injection, partial injection of dependencies can possible, means if we have 3 dependencies like int, string, long, then its not necessary to inject all values if we use setter injection. If you are not inject it will takes default values for those primitives1. In constructor injection, partial injection of dependencies cannot possible, because for calling constructor we must pass all the arguments right, if not so we may get error|
2. Setter Injection will overrides the constructor injection value, provided if we write setter and constructor injection for the same property [i already told regarding this, hope you remember ] But, constructor injection cannot overrides the setter injected values
3. If we have more dependencies for example 15 to 20 are there in our bean class then, in this case setter injection is not recommended as we need to write almost 20 setters right, bean length will increase. In this case, Constructor injection is highly recommended, as we can inject all the dependencies with in 3 to 4 lines [i mean, by calling one constructor]
4. Setter injection makes bean class object as mutable [We can change ] .Constructor injection makes bean class object as immutable [We cannot change ]
|Help us improve. Please let us know the company, where you were asked this question :|
|Like Discuss Correct / Improve spring dependency injection inversion of control Sofi HCL Technologies Tata Consulancy (TCS)|
|What is Dependency Injection or IOC ( Inversion of Control ) ?|
|Name few Dependency Injection frameworks ?|
|What are the benefits of Dependency Injection or IOC ?|
|What are different types of dependency injections ?|
|What are the various Auto Wiring types in Spring ?|
|What is the difference betweeen @Inject and @Autowired ?|
|Which of the following Java features facilitates Dependency Injection - Inheritance or Composition ?|
|What are the different ways in which dependency injection can be done using Spring Framework ?|
|Which of the OOP's features facilitate dependency injection ?|