Basics of Object Oriented Programming
Basics of Object Oriented Programming
CHAPTER ONE
1) Data moves freely around the program and therefore vulnerable to any changes caused
by any function in the program
2) It does not model very well the real-world problems.
OOP was invented to overcome the drawbacks of the POP. It employs bottom-up programming
approach. OOP treats data as a critical element in the program development and does not allow it
to flow freely around the system. It ties data more closely to the functions that operate on it, and
protects it from accidental modification from outside functions. OOP allows decomposition of a
problem into a number of entities called objects and then builds data and functions around them.
Object – Oriented approach views a problem in terms of objects involved rather than procedure
for doing it.
That is Object is considered to be a partitioned area of computer memory. It stores data and
set of operations that can access that data. Since the memory partitions are independent, the
objects can be used in a variety of different programs without modifications.
Since these classes, which are the user defined types use the concept of data abstraction
they are known as Abstract Data types.
2. Encapsulation
The wrapping up of data and functions (that operate upon the data) into a single unit (called
class) is known as encapsulation. This is a way to implement abstraction. We can access the
data only through the functions (known as member functions) that are combined along with
the data. They cannot be accessed directly.
Thus we can say that data is hidden and so it is safe from accidental alteration. Data and
functions are said to be encapsulated into a single entity. This insulation of the data from
direct access by the program is called data hiding or information hiding.
3. Inheritance
This is the capability of one class of things to inherit capabilities or properties from any
other class.
E.g.:
Vehicles
Car Cart
Roles:
Its capability to express the inheritance relationship, which makes it, ensure the
closeness with the real-world models.
Another is the idea of reusability. Inheritance allows the addition of additional
features to an existing class without modifying it. This is possible by deriving a
new class from the existing class one. The new class will have the combined
features of both the classes.
The third reason is its transitive nature. If a class A inherits properties of another
class B, then all subclasses of A will automatically inherit the properties of B.
4. Polymorphism
The term means the ‘ability to take more than one form’. Thus Polymorphism can be defined
as the ability for a message or data to be processed in more than one form.
Consider the eg: Dog and Cat both are subclasses of Animal. Now the message ‘see through
daylight’ when passes to these classes will behave alike. But the message ‘see through night’
will behave differently since dogs will not be able to view at night whereas cats can.
Types of Java Applications
There are mainly 4 types of applications that can be created using java:
1) Standalone Application
2) Web Application
An application that runs on the server side and creates dynamic page, is called web
application. Currently, servlet, jsp, struts, jsf etc. technologies are used for creating web
applications in java.
3) Enterprise Application
An application that is distributed in nature, such as banking applications etc. It has the
advantage of high level security, load balancing and clustering. In java, EJB is used for creating
enterprise applications.
4) Mobile Application
An application that is created for mobile devices. Currently Android and Java ME are used for
creating mobile applications.