The short answer is yes.
As a starting point you could use asm library. This is a usefull presentation http://s3-eu-west-1.amazonaws.com/presentations2012/30_presentation.pdf
This library can be used for instrumentation, inspection and dynamic code generation which can then be loaded using a classloader.