How is loose coupling achieved using interfaces in Java when an implementation class is mandatory and bound to interface contract?
The key point is that an interface doesn't just allow you to write one class which implements it, it allows you to write several.
When you have code which interacts with a class by using an interface, that code is able to work together with any class which implements said interface, regardless of how it implements it. That allows you to feed different classes to the same code without having to modify it.
Please note that interfaces are not the only way to reach a loose coupling of components. Loose coupling just means that components are able to work together without assuming anything about the internal workings of each other. You do that because the more your components treat each other as black boxes, the easier it becomes to do changes at one component without affecting any others. Interfaces can be one tool to work towards this goal, but neither are they required, nor are they the only tool which is worth mentioning in this regard.
The implementing class is able to choose HOW to implement the functionality.
public interface PersonRepository {
Person getPerson(String name);
}
Could be implemented by reading through a CSV file or by querying a database. The object which needs the person does not care how the person is found or loaded just that it is.
Hence it is deemed to be loosely coupled.
If it was tightly coupled it would need to know how to construct a SQL query or read a CSV file.