Explain the concept of reflection in Java and how it is used.
Reflection in Java allows you to inspect classes, interfaces, methods, fields, and other elements of the code during runtime. It enables you to manipulate classes, methods, and fields dynamically, without knowing their names at compile time. Reflection is often used in frameworks and libraries for tasks like dependency injection, serialization, and unit testing.