Saturday, September 1, 2007


Hum, It has been few years, every one is talking about blogs, blogs blogs every where... And today I decided to put my thoughts to a piece of paper, and i am here :). Ya My first blog, I too a blogger from today!

Just before getting here,it was all about what to blog. And finally I decide to blog some thing related to my bread and butter. So here I am about to talk about basics of Object Oriented Programming. The content I am about present is something general,which is applicable to all oop languages.

A few lines of code, which I used 'here and there' is in "java", which is my most favorite among a dozen. The major reason is, it is the one with least number of key words.

A variable and an object.

an object variable and an object are totally different entities.
When you crates a variable of a particular type, you are creating a variable which can store address of an object of that particular type.

MyClass obj1;

Here obj1 is a value holder which can store address of an object which is of type MyClass

Now see let see what happens when create an object and assign it into some variable

MyClass obj1 = new MyClass();

We already discussed about the left part of assignment which is "MyClass obj1". Now about the right hand side. When you say new MyClass(), an object of MyClass will be created and the memory address referring to the object will be returned.

let the base address of newly created MyClass object be 0x100. So our above expression becomes

MyClass obj1 = 0x100;

I.e. obj1 now contains 0x100, a reference (address of) to MyClass object. More clearly value of obj1 is 0x100. This is the only relation between obj1 and newly created object.

Now we will polish our idea through another piece of code.

MyClass obj1 = new MyClass();
MyClass obj2 = obj1;


Here obj2 is another variable which can store address of an object whose type is of MyClass. We are assigning value of obj1 into obj2. So now obj2 will get the content 0x100. Now both obj1 and obj2 points to same object.

MyClass obj1 = new MyClass();
MyClass obj2 = obj1;
obj1 = null;

In the above code am setting value of obj1 to blank. I.e. obj1 no longer points to any object. But we can still access the MyClass object which we created through obj2, since it still holds address the object (0x100).

Hoi! That is it, my first blog is ready to ship.

Some of you may feel the content I presented here is something which even a baby knows. I know this is very basics, but I breath this every moment and for me this is some thing very big, which enables me understand anything related to oop around me!

Happy reading! [Hope you will spend time to comment on my first blog]

4 comments:

Unknown said...

Ramaa... karl marx has said once, for a bureaucrat, the world is a small "object" to be manipulated by him !

orthaal nannu :)

Congrats ! spelling mistake illathe ithrayum ezhuthiyillee... (randennam undu.. that i ignored)

Lloyd said...

Rama Good start ! keep posting

JP said...

SriRaman,

Good start.Nice little article.Keep posting.

Thanks
Prashant
http://prashantjalasutram.blogspot.com/

moments said...

Prashant,
Thanks a lot for your valuable time and support.

Thanks
moments