Saturday, August 28, 2010

Inheritance implementation in Java

"Understanding a concept does not mean merely remembering the definition, it includes knowing the working or application of that concept."  -  Come closer to the screen, look at above sentence and try to understand (its the definition of understand) it. I know its recursive but I will clarify it with the example of Inheritance:


Assume your instructor has chosen you for questioning, and he demands: "Explain Inheritance?". You somehow manage to utter some words "reuse", "code", "hierarchical relationship" and get the clean cheat. You get seated and wipe-off the perspiration.

If this scenario is common then you are a victim. You merely know the definition or have faint idea but do you know at what stage is inheritance comes in to the picture? Apart from by-hearting the definition, it is equally important to know how a concept is implemented. Lets have a look @ how Inheritance is implemented in Java. Beginning with process of compilation,



Assume class "Child" is child of class "Parent". We define both classes as follows:

class Parent  class Child extends Parent
{ {
  int a; int b;
} }


Now going by definition, we know that sub class inherits all the members of parent class, hence "Child" class should have two members conceptually:
int a;
int b;

And to verify it we create an object and try to access member a, and it works.
child ob = new Child();
ob.a = 10;



Weighing both sides,
  • At code level there is no member 'int b' in child class
  • At execution level Child class has the member 'int b'.


This gap is filled at compilation level and Java handles Inheritance at compile time. Thus,

Compilation includes defining structure of each class. The moment javac senses one class to be child of another, it adds all members of super class to structure of child. Thus the class layout after compilation would be...


class Parent   class Child
{ {
int a; int a;
} int b;
}


Getting This?        YES or NO???       Ok,   Repeating once more,


Inheritance (sub-class has all the members of super-class) is detected at compile time. If any class is found to be "child" of super-class, all members of super-class is added to structure of child-class. Finally all layouts is written to .class file and thus saved.


Now that's called Understanding Inheritance. I know you will let me know what have you inherited from this post via comments.

Thursday, August 19, 2010

Sign Extension in Java

Sign extension is a rule in Java by which widening conversion is carried out. While we are on the mood to know something, Let us see the whole process by an Example.

Wednesday, August 18, 2010

Combating one of the most common Programming Mistake

Lets begin with question.

Do you know the most common programming mistake? Try to recollect the times when you used to compile your baby size programs and print Hello World.

Didn't get it? Its omittance of semicolon at the end;

What I am about to share is solution to just another big common mistake, staking programmers scared sleeps.


The scenario:
After hapless efforts, tonnes of Page Dn and Page Up, when your eyes swell of digging screen and at last you encounter the villain: "if(x=0)". You take a deep breath and after adding the required '=' the program finally complies.


The Solution:
In order to avoid this just use a simple rule: always put conditions with constants on left: "if(0==x)". It might look bit odd but has the 'miracle' thing. It will always generate error if you put single '='. Here's how,

Lets assume you forget to put the second '=' (No way if you have read this post) and you try to compile, it would throw an error because "if(0=x)" is illegal in language - you cannot assign variable to constant.


Hence always keep these practices:
  • Use (0==x) in conditions
  • Read this blog everyday before brushing

That said will save you real time.

Monday, August 9, 2010

How to create 'Special' folder.

Want to create a folder that can never be

  • Created(By others)
  • deleted(By others)
  • Renamed
  • Moved
  • Copied


Read on…….

"Tab Candy" - New feature in Firefox 4

Without a doubt “Web browser” is most speedy developing software ever. New features are being added everyday and one such feature is “Tab Candy” introduced in upcoming version of popular browser Firefox 4. Before exploring the subject let us know what scenario lead to its necessity.



We often find ourselves reading articles, Checking emails, Social Networking, Downloading etc. all in several tabs open in one browser window. Its fine up-to 8 to 10 tabs but when it gets more, the problem arises. To tackle this situation “Tab Candy” was proposed.

Tab Candy is basically tab grouping. You put Email tabs into one bunch, Facebook-Orkut-what-not into second, News–Reader into third and so on. Make them as you wish.


To see it in action is even more fascinating, just press Tab candy button and you zoom out with thumbnails of all tabs. Pick similar tabs and drag them outside boundary to form another group.



Click on any tab to zoom in and viola! Only tabs from that group are shown. Feel like someone is buzzing you, zoom out and select Social-Networking group, only tabs in that group will be shown.


Thus it is very much similar to Desktop-switching concept used in Linux where many windows are open at a time but they can grouped and one group shown at a time. This certainly keeps us on track without irrelevant things.

Whats more, you can setup a layout with groups at predefined position and thus resulting into something like this




The future?

Tab Candy project is further developed to enable tab-group sharing, so that I Click-Click-Click at home, reach the office, Click-Click-Click and session is restored. Search feature is also being added to interface.

See it in motion @ http://bit.ly/9d3xFi

Working with 100+ tabs easily-effectively-efficiently(read that again) is the “Whats next” of browser.