Thursday, January 31, 2008

JMX and Introspection Versus Reflection

The difference between Java introspection and reflection is sometimes confusing and the two terms are often used interchangeably. This is not really a problem in most cases from a practical perspective, but there are cases where it does matter and the difference is interesting to note from an intellectual point of view.

Java SE 6's JMX Platform Server provides both a ReflectionException and an IntrospectionException. Both of these JMX-provided exception classes extend the checked JMX-provider exception JMException. The extends directly while extends which extends JMException.

There are a few good resources on the differences between introspection and reflection, though for the purposes of most of us writing JMX-enabled code, these are not usually significant.

In Java Reference Guide: RXML, Stephen Haines provides a nice overview of Reflection versus Introspection.

The Java Tutorials Reflection API Trail talks about reflection (including situations in which it is not appropriate) and the Java Tutorials JavaBeans Concepts Lesson also talks about introspection on JavaBeans and the use of "core reflection" to do this.

Dr. Ira Forman and Nate Forman provide a nice article called Java Reflection in Action (same title as their book) that provides an interesting description of Java reflection and introspection. They refer to reflection as "introspection followed by behavior change." This best fits my understanding of the reflection and introspection and seems to align well with the Javadoc descriptions for the JMX classes cited above.

No comments: