Thursday, September 15, 2011

Implementing Aspect Oriented Programming Framework - Java Instrumentation

What is Aspect Oriented Programing: Aspect Orented Programing or AOP is a design pattern or programming practice, in which the code for cross cutting concern is separated out from the main program logic, thus effectively reducing the program complexity. Now what is a cross cutting concern? They are application non-functional requirements that apply to multiple functionalities. A simple example would be logging. Logging is done whenever some predefined things happen (for example a method is invoked). Normally, every method that is invoked would have to contain the code for logging. In AOP, we write the logging code in a separate method may be in a separate class and then configure our AOP framework to do logging whenever a method is invoked. There are so many good tutorials available on AOP, one of which is here. However, in Java SE environment, it certainly requires a change in the method's byte code made by the AOP framework. I will demonstrate how an AOP framework performs load time weaving (changes byte code during runtime).

Thursday, August 25, 2011

Manipulating Java Class Files with BCEL - Part Three: More About BCEL

This is the third article in the BCEL series. You can read all here. Since I have covered the basics, I will accumulate the points left now. I will discuss about local variables, fields, methods and jump instructions.

Thursday, August 18, 2011

Manipulating Java Class Files with BCEL - Part Two: Expressions

This is the second article in the series of articles on Apache BCEL. If you have not read part 1, read it here.

Expression Processing: Expressions are key part of a language. In this article, I will discuss how expressions are compiled into java byte code. I will also cover a little bit about compilation process. At the end, I will go through the steps and create a compiler for numerical expression.

Thursday, August 11, 2011

Manipulating Java Class Files with BCEL - Part One : Hello World!

What is BCEL: Apache BCEL or Byte Code Engineering Library is a library that enables simpler manipulation of java byte code. Now the question is, why manipulate byte code? There can be a million of reasons. For example, you might want to insert some profiling code in the class file. Or you might want to write your own language that compiles to java byte code. You can also provide some attractive extension to some framework you are creating. Or you can even be more creative than I am and do something that I cannot think of. But for that, you must first understand how java class files work.

Since it is a BCEL tutorial, get the BCEL library first from here


Manipulating java byte code directly is not trivial in nature, so I decided to break the tutorial into a series. This one is the first - the hello world. Keep in touch to learn more.