Java's Reflection API allows you to write code that adapts to runtime conditions. And you don't have to be working in a large-scale application to reap its benefits, either. Find out how reflection can allow your applications to be more robust and flexible.
by Doug Tillman
March 31, 2005
evelopers aren't issued crystal balls with their computers, which makes anticipating future changes to business rules or an application's runtime environment challenging. Fortunately, what your code knows at compile time doesn't need to limit your application's ability to react dynamically to changes in the runtime environment.
Techniques for reading initialization or properties files are well known but many developers are unfamiliar with Java's Reflection API. Reflection provides a means to significantly enhance your code's ability to respond to the runtime environment; differentiating program behavior based upon the user or server or any other runtime variable. This article will explore how the LoginContext class of the Java Authentication and Authorization Services (JAAS) leverages the Reflection API to implement a responsive security services layer by loading login modules on demand rather than at application startup. (JAAS is part of the core JDK as of Java 1.4 and is available as a separate download if you're using Java 1.3x).
It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com. Already a member?
To become a member of DevX.com create your Member Profile by completing the form below. Membership is free!