Sunday, October 21, 2007

Java programming dynamics

A very good series of articles about Java reflection (how to access a class' members and methods by name), class loading, and bytecode manipulation can be found at the IBM pages (April '03 - June '04):

If you want to learn something about the one the reasons that make Java such a powerful languate, read it. These features are, e.g., used by JEE servers or persistence frameworks to automatically determine the methods and fields to be deployed, for accessing the Java 5 @Attributes (not in the articles, yet comparably easy), and to code or derive proxy classes for the deployed services. Part 1:
  • .class file format
Part 2:
  • Hierarchy of class loaders
  • fields and methods by reflection
  • security of reflection, and how to disable it (e.g., to access private members(1))
  • reflection performance
Part 3:
  • Using reflection for processing command line arguments
Part 4:
  • Inject bytecode into existing methods with javaassist
  • introduce method timing into compiled code
  • Java Aspect Oriented Programming (AOP)
Part 5:
  • Intercepting class loading
  • modifying class bytecode on load
  • introduce method timing into code at load time
Part 6:
  • Code conversion
  • class mutilation made easy
Part 7:
  • The Byte Code Engineering Library (BCEL) (also have a look at ASM, also, as this library tries to correct BCEL's deficits)
  • using "coding constructs" instead of "bytecode assembler"
  • the verifier of BCEL
  • disassembling with BCEL and its graphical display
Part 8:
  • Reflection on performance
  • building a glue class
  • improved performance of code generation vs. reflection
Notes: (1) I know you shouldn't do this, especially not with human men ...

No comments: