Updates
Latest Tweet
What's New?
Check out for latest innovation, a computer based training video collection
Like this Page
Java Reflection in Action Review by Ganeshji Marwaha
Neat little guide to reflective programming
Java Reflection is an extremely powerful API that most modern frameworks like Spring, Hibernate, XFire, JUnit etc., use as its core enabling technology. We all use these frameworks for our applications, but never really bothered to see how the framework achieves certain things that it does.
This might be because we think reflection
1. is complex --> maybe it is, but do you think that it should stop you when it can cater more elegant/flexible/reusable code.
2. is an advanced topic --> maybe it is, that is why we are learning this after learning the basics first.
3. performs poorly --> Latest versions of java has considerably improved reflection API's performance. Also, there is an entire chapter dedicated to performance in this book.
4. for framework programmers only --> Not any more
5. is not necessary --> It is not necessary until you learn it. Once you learn it, you will wonder how you even lived without it.
Today, Reflection is being used even for application requirements such as
1. Flexible and re-usable code
2. Implementing cross-cutting concerns
3. Validation
4. Dynamic addition/modification of functionality... and much more...
In this book, the Foremans do an excellent job of preaching the advantages of using reflection. They are pragmatic in that, they keep you adviced that reflection is a magic-bullet only when used for the right purposes. The chapters are well organized and starts with the basics and goes all the way to the most advanced concepts.
The authors start with a simple scenario where reflection could be useful. Using this scenario they teach the basics of Class and Method objects, how to find the class of an object at runtime, how to invoke a method on that object etc. The next couple of chapters takes "Serialization of Java objects to XML" as the use-case and explains the concepts of accessing fields reflectively, dynamic class loading, dynamic object construction etc. Moving onto the advanced concepts, the author takes you through a tour of dynamic proxies, custom classloaders, call stack introspection, performance metrics etc.
At this point, the authors stop to point out the shortcomings of the java reflection API and show you how to use Code-Generation technique to work around those limitations.
Finally, the authors give a sneak-peek at java 5 and how it is going to change the reflection API.
I have a couple of suggestions for this book though
1. This book needs a java 5 update
2. Java beans API could have been discussed at a shallow level atleast. Though java beans does not belong to the reflection api, it is <<-- well -->> indirectly related.
Overall, I found this book easy to read, rich in content, pragmatic in advice and i highly recommend it to any "moderate to experienced" java developer who wants to construct code that speaks for itself.