Tuesday, January 4, 2011

Java : A live language

Java is a language which can be understood only if it is learned by relating its different aspect with the real life.

Just for example, everything in the Universe is made by the almighty GOD, in the same way every class has directly or indirectly one father/super class i.e. java.lang.Object. If we create a singl class, internally it is extending the class java.lang.Object and getting the basic required nature from the super cosmic class 'Object'. If we create a sub-class 'B' of some class 'A' i.e., if B extends A then we see that indirectly class B is grandson of class Object as class A is the subclass of java.lang.Object and class B is the child/subclass of A. So, in a class hierarchy, every class will ultimately be the subclass of java.lang.Object class.

In real life every child has a single father, in the same way, every designed class in java has a single direct super class. So, as in real life, we see God, ...., Grandfather, father, son, grandson and so on...; in the similar way in java the tree structures looks alike i.e., java.lang.Object, custom class, subclass, subclass's subclass and so on. Here, we see that each class has a single father. I mean, java also supports the single inheritence i.e. a subclass can't be created by extending more then one class.

One person can have only one father. Suppose, the son inherits/learns music from his father. So, in java this is inheritence feature. a subclass can have inherited behaviour from its super class. Now suppose if the son who inherits playing music from his father, goes to learn computer from some other teacher then, the same person know two different things, one is music inherited from father and second computer from some other teacher. Thus, a person can add more ability in his life by getting knowledge from more then one people. Just the same concept here in java as interface. A subclass can inherit some feature from its super class and can implement the behaviours from more then one interface to make itself more able.