Java Reflection Examples
Java Reflection is used the extensively in following areas:
- JUNIT JAR-Junit 3.0 uses reflection to find methods that start with" test".The algorithm was changed in 4.0.Now reflections are used to find methods with @ test annotations.
- Java Editors and IDE: Most of the java editors like eclipse,Netbeans and others use reflection to populate the methods associated with the class.For example in most of the java editors when you type "classname." and press space or tab you get all the methods associated with it.The method suggestion is shown using java refelection.
- Java Ant Build Files: A user can use taskdef property to instantiate and compile a user defined task.
- Spring framework:Spring uses reflection to create an Object of each Bean.The spring xml file has the classname attribute which is read to create bean objects.All the Bean Objects will be created using a default constructor and the proprties of the objects are examined.
- Runtime code generation:This is used by IDES and webservers to convert jsp pages to servlets.
- Aspect Oriented Programming-AOP-Generate Proxies for classes and interfaces,spring uses this techniques