Showing posts from June, 2011

Inheritance versus composition in Java

are two important concepts you should swear by. Both help us to relate classes and achieve code resuse. But which one do we use?
Comparing inheritance and composition.
In inheritance, a change to the method interface/definition of the superclass ripples down to the sublasses (if the method is overriden) and also to the clients of the sublasses thus making the superclass very fragile. In case of composition the change is limited to the containing class and not the clients.With inheritance, you cannot change the overriden method in the subclass without changing the superclass; reason it wont compile. With composition, you can change the interface of the method in the containing class that uses the method/behaviour of the contained class without touching it.In case of inheritance the classes are bound statically at compile time or as soon as the subclass is defined and will remain with the subclass till its lifetime. where as in case of composition, the behaviour can be changed at runtime.…

Class Loaders - simplified - part 2

In my last post I said I will be discussing about NoClassDefFoundError and the ClassNotFoundException
You can load the classes in two ways one is static loading and second way is to dynamically loading the class. Static loading - load a class statically using the new operator.Dynamic loading - programmatically loading the class using the class loader functions at run time.Using Ex Class.forName/ClassLoader.findSystemClass/ClassLoader.loadClass You can get NoClassDefFoundError for the following reason 1) You have not set the class path, so the class loader cannot find the .class file ( TestClass) 2) You have set the class path, but the class path does not contain the .class file/jar does not contain the specified .class (the call to the new operator fails) 3) It could also happen if the class fails to load as the static initializer block fails for some reason.

You can get ClassNotFoundException if 1) You have set the class path, but the class path does not contain the .class file/jar does not…

Class Loaders - simplified - part 1

As discussed in my previous post, class loaders is one of the components of JVM. It is responsible for finding and loading the class at run time.
Classes are loaded into the JVM as they are referenced by name in a class that is already running in JVM. The first class is loaded into memory by invoking the static void main method of the class. All subsequent classes are loaded by classes which are previously loaded and running.
The following class loaders are created by the JVM Bootstrap or primordial class loader: Is the default class loader which is associated with the JVM. You can hook your own custom class loader instead of the default. All the JDK internal classes java.* packages i.e the ones that belong to rt.jar or i18n.jar are loaded by this class loader. (as defined in the sun.boot.class.path system property)Extension class loader: loads classes that are part of the extensions directory typically the lib/ext directory of the JRE are loaded by this class loader. (as defined in the…


Java Virtual machine -is an abstract computing machine. It is the component of java technology that gives it hardware and OS independence. It has its own instruction set and manipulates various memory areas at run time.
The architecture as defined in the specification makes it possible to have different JVM implementation for different hardware platforms.The architecture of the JVM as defined in the specification is shown in the diagram below
It consists of Class Loader subsystemRun time data areasExecution engineNative method interfaceNative method libraries.Class loader subsystem - is responsible for loading types (classes and interfaces). The .class files adhere to fix format and it contains JVM instructions or byte codes, a symbol table and other ancillary information. Execution engine - is responsible for the actual execution of the instructions contained in the method of the loaded classes. Run time data areas - the JVM organizes the memory it needs to execute a programs into vari…

Java Platform

is a platform for java development. It is a software only platform which is ported on hardware platforms It comprises of two major components JVM - Java virtual machine - it is the component which add portability aspect to Java. JVM understand byte codes (compiled .class files from .java classes). Byte codes are the machine language of the JVM. JVM then interprets byte codes to the actual underlying machine language. Compilation happens only once and interpretation happens each time the program is executed.Java API - a set of classes written using java and which runs on the JVM. It consists of lot of useful classes which help us in development of applications etc.You can find useful references

Concurrent call exception using Seam and JSF

I got this exception, while working on a Ajax+JSF+Seam project. I ignored it for a while till it came back haunting at the UAT.
A little investigation into the exception and googling help me find the answer. Here is what happened, I had a ajax component which was taking a long time to render the response, in the meanwhile another request was sent to the server through some other component action ex a submit button, this call failed to render the response, reason being the first call had obtained a lock in the render_reponse and hadnt released it, so the second call failed to obtain a lock and hit back with the exception.
You could solve this in one of the following ways,
1. Showing a wait dialog so that the users understand that there is some processing going on.
2. queueing the request, a4j has a component named 'queue' which you can leverage.

If there are better ways to handle this, I will be glad to add it to my kitty.