In this section we are going to illustrate how the real life objects are the key to understand object-oriented technology
Objects are the part of our day to day life, these are the real world entities around us. Technology, records, human beings, and even the implemented concepts all are the examples of objects. For instance, A CEO of any company can take a view of his company's policies, employees, buildings, records, and beneficial packages as the objects. Similarly a software developer does analysis, designing, coding, testing and also looks for the future scope of that project as objects. Even a toy is an object for a child.
Real-world objects share two characteristics: They
all have state and behavior.
For instance Lions have state (name, color, breed, hungry) and behavior (roaring, fetching etc). Cars also have state (current gear, current speed) and behavior (changing gear, changing speed, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming. Objects are key to understanding object-oriented technology. Just look around and you'll find a lot of examples of real-world objects: cat, desk, television set, car, pen.
Now, we have modeled these real life entities in the
computer languages as software objects or simply objects. Precisely, an object
is a software bundle of related states and behavior in which variables are just
like states and the methods are just like behaviors (providing some
In an object, variables store values for later use and methods are the unit of codes that provides a particular functionality. We can say objects are the basic units of the object-oriented technology.
Here is an additional information about Objects that we can create multiple objects in any single java application to perform many task like implementing a GUI, any operation on information and many more.
We all use classes to do the perfect work in object oriented programming. A class is follow the structure of object because it also a combination of variables and functions. We can define the term of variables in class as the properties and function is just as a method.
Now we are going to explain, how to represent objects in Java using classes, methods, and properties. Here we just take a look at the definitions of related part of the object oriented programming such as abstraction, encapsulation, inheritance, and polymorphism as follows.
Information about an object can be accessed in a manner that also give a generic way that how data is stored from and how it is accessed and used.
The information about an object and functions that manipulate the information are stored together. It is also a ability of a object to hide its data and methods from the rest of the world.
Classes can inherit properties and methods from one or more parent classes. We can say that certain characteristics that are passed on from one context to another is called inheritance.
In the term of object we can say that Polymorphism allows objects to be represented in multiple forms.
Till now it is much clear that the object has its own importance in object oriented programming now there are some key advantages of objects are describes as under:
What is a Class?
In the real world there may be many objects of the same basic kind. For
example, there are many CD players like yours, all made by the same
manufacturer. In object-oriented terminology, your personal CD player is
an instance of the generic class of CD players of that make. Each
instance has its own state (e.g., each may have a different CD loaded) but they
all have the same methods defining their behavior.
When a manufacturer builds a CD player, it uses a blueprint to know how to construct it. All CD players of that same model can be built using the same blueprint. Likewise, in object-oriented programming you need a blueprint for constructing object instances. These software blueprints are called classes and are written by you, the programmer.
For example, when writing a CD player class, you would declare instance variables to hold the player's state (title of CD loaded, current track, etc.). You would also declare and write instructions for the methods that the CD player implements (play, skip, etc).
After writing the class definition, you can use it to create objects of that class by instantiating them. When created, each object has memory allocated to it to hold its instance variables (i.e., its state). The state of each object is separate from that of the others. After an object is created, you can call its instance methods to have it do something.
In addition to instance variables and instance methods, the class can define static variables and static methods. Static variables are not duplicated in each instance. They store properties that belongs to the class as a whole. Each instance of the class will get the same value when accessing a static variable. Collectively, instance variables and static variables are referred to as member variables because they are members of the class.
Static methods are similar to instance methods except the class, rather than an instance of that class, executes the method. Because the class itself is executing the static method, it cannot use any instance variables, only static variables. This is because there is no instance to get the variable values from.