To answer your questions in simple words,
For #1 : Dependency injection is something about satisfying the need of one object by giving it the object it requires. Let see an example :
Generally in an enterprise application we use an architecture where in services call a DAO layer and DAO does all the database related stuff. So service need and object of DAO to call all the DAO methods.
Considering we have an entity object - Person.
Lets say we have a DAO - PersonDAO.
public interface PersonDAO { void addPerson(Person person); void updatePerson(Person person); void deletePerson(int personId); }
and a service - PersonService.
public class PersonServiceImpl { private PersonDAO personDAO; public void addPerson() { //some code specific to service. //some code to create Person obj. personDAO.add(person); } }
As you can see PersonService is using PersonDAO object to call its methods. PersonService depends on PersonDAO. So PersonDAO is dependency and PersonService is dependent object.
Normally in frameworks like Spring these dependencies are injected by frameworks itself. When application context is loaded all these dependency objects are created and put in Container and whenever needed they are used. The concept of Inversion of Control(IoC) is very closely related to Dependency Injection because of the way the dependency object is created.
E.g You could have created the PersonDAO object in PersonService itself as PersonDAO personDAO = new PersonDAOImpl();
But in case of spring you are just defining a property for PersonDAO in PersonService and providing a setter for it which is used by spring to set the dependency. Here the creation of dependency is taken care by framework instead of the class which is using it hence it is called Inversion of Control.
For #2 : Yes. You are right.