Java Reflection Examples

Java Reflection is used the extensively in following areas:


  1. 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.
  2. 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.
  3. Java Ant Build Files: A user can use taskdef property to instantiate and compile a user defined task.
  4. 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.
  5. Runtime code generation:This is used by IDES and webservers to  convert jsp pages to servlets.
  6. Aspect Oriented Programming-AOP-Generate Proxies for classes and interfaces,spring uses this techniques





Comments

  1. Interesting, didn't know that all of these were different examples of the use of java reflection. Another good reference for this:


    Example of Java Reflection

    ReplyDelete

Post a Comment

Popular posts from this blog

Spring MVC- Redirect from one controller to another

Jquery Table Inline Edititing