Wednesday, December 10, 2008

What is an Object

Welcome back to Java Code Online. Many of my friends and readers often ask me that "What is an Object?". Understanding the basics of Object is compulsory for getting a hold on the Principle of OOPS and Java itself.

Java is totally built on the fundamental of Object Oriented Programming(OOPS), and OOPS depend upon the understanding about the "Object". So getting a hold on this question is important.

I will start with real life examples, everything that you can see in this world is an Object. Just look around yourself, your bike, table, chair, television, even you yourself and me too are Objects. Every entity is an Object. Now Objects have two basic properties. They are:
1. State
2. Behavior

Whenever you need to access and understand an Object, just ask yourself what are the possible state of this Object and what could be the possible behavior of this Object. For example a table lamp can have two states on and off, while there could be two possible behavior of the table lamp, turn on and turn off.

Similarly for a cat the possible states could be hungry, color, breed, etc. While there could be many states like wagging tail, chasing mouse, etc.

The state of an Object defines what the Object "knows", and the behaviour of the Object defines what the Object "does". In Java a class is used for making an Object. Whatever the Object knows are its instance variables and whatever the Object does are its methods.

The methods In Java operate on the Objects state and provides a mechanism to the outer world to access and operate on them. If you are confused between a class and an Object, then read my previous post on Difference between an Object and a Class.

Keep in mind that an Object is the core of Java, so make sure to read this article properly so as to get a proper hold on "What is an Object?".

I hope that this article was beneficial in explaning you about What is an Object. If you liked this article then do leave a comment. For more information on Java, keep buzzing Java Code Online.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.