h1

Dynamic modification of a Java class properties at runtime

We all know that in java usually has its code contained in a .class file format . The JVM is responsible for loading the class and converting it into native machine code to make it executable.Basically ,The javac tool reads class and interface definitions, written in the Java programming language, and compiles them into the platform independent bytecode class files.For more on classloading follow the link:http://www.onjava.com/pub/a/onjava/2005/01/26/classloading.html 

Now, before runtime we have our java classes byte code format ready to be acted upon by the underlying JVM.Byte-code has a language of its own,and it is possible to manipulate the byte-code and effectively not only add properties – but possibly change code also ! before we actually allow the classloaders to take their course. There are libraries for doing so too – e.g. Apache BCEL . The whole of .class file format and manipulation is explained in:

http://jakarta.apache.org/bcel/manual.html

 [In fact there are even libraries to create and compile classes from scratch. Remember that JSP are compiled into Servlets by the appserver. Now, in JDK 6, there is also a compiler API to programatically invoke the compiler too] However, everything has its pros and cons — all this is stuff only for high-end applications like the app-server etc. Normal business application – not only don’t need these stuff — but actually should NOT depend on this stuff in the first place. For business applications things like type-safety, debuggability, managability, maintainability etc. are more important —- all of which you loose the moment you do byte-code manipulation !   

One comment

  1. [...] of a Java class properties at runtime « Flexibility thy strength,rigidity thy super strength Dynamic modification of a Java class properties at runtime « Flexibility thy strength,rigidity thy … Published [...]



Leave a Comment