in Core Java

Introduction to OOPs and Java

Introduction to Object Oriented Programming


Introduction to Oops:

"Welcome to the Object oriented world – a virtual world". These sound like words from the movie Matrix – right. Yes, the moment when you made a decision to learn about the Object oriented programming, you are going to be in two worlds – The real world – what you are in and a virtual world where your objects act like what you have scripted.

The learning and programming in Object oriented programming model is going to most excited if you think in objects.

The real aim of the programming language is to simulate the real world into the computers – Right!. Yes, think of the game Road rash in which your car speeds at 140 kmph and when hits a tree or a lamp post, its speed comes down to zero as in the real world.

Object oriented Programming is the most successful among the programming models in helping to simulate the real world into the computers using programs.

Some of the languages which object based programming languages are given below:

  • Smalltalk
  • C++
  • Java
  • .NET


Before Object oriented programming was born, there were structural programming, procedural programming and modular programming.

Structural Programming:

The statements in this programming  model are executed one after the other. To access some functionality or expression, GOTO statements will be used which makes the programs too complex. Fortran is based on Structural programming.

Procedural Programming:

To overcome the complexity of the structural programming, procedural programming has evolved where the reusable functionality is separated as procedures and can be called anywhere using call back statements. These are also called functions.

Modular Programming:

Maintaining a huge number of procedures can be cumbersome. Modular programming helps to group the procedures to keep them as modules.

Issues with these programming models:

 The major issue with these programming models is the lack of data security.  The data can be accessed by any procedure and there was no proper way of assigning the attributes.

Evolution of Object oriented programming:

All the issues faced by the other models of programming are solved in Object oriented programming.

Its was in the year 1980, the Object based programming language – Smalltalk was released followed by C++.


Thinking in Objects

To program in Object based languages, it is extremely important to understand what are objects.

A programmer should think and keep in mind that "Everything in this world is an object". We are living with many number of objects around us and use a lot of them to make our daily life keep going.

For example, we use car to reach to office, use pen to write, mobile to make a call.

So, everything around us are objects including ourselves. 

The next question is that what really an object has?  Every object has some properties and behavior.

Let us consider a pen we use. It has a price, name, color, weight etc., The responsibility or behavior of pen is to write.

We use pen to write.

So, Pen as an object has price, name, color and weight as properties which can be stored using data types like int, string, double respectively.

The behavior write can be represented as a method write() in the pen. This behavior is there to be invoked by other objects like student, teacher etc.,

Let us consider a small scenario of a college where a Student leans from a teacher who teaches the students. Students use pen to write the exam and teachers use pen to correct the papers and both use car to reach to college.

In the object oriented world, any object can invoke any object in the system.

Read the detailed article on identifying the objects in a requirement.

Objects are instances of types

Every object in the system should belong to a type. So what is a type actually?

Let me explain this with a simple scenario. You have document written by your grand father in his hand writing. Now you have took three photocopies of that document. We call the photocopies as instance of the original document.

In the same fashion, a type is a class in programming which defines the properties and behavior of the objects and any number of instances (objects) can be created using the new operator.

Refer to a detailed article on Classes and instances in OOPs.

Four pillars of Object oriented programming

To represent the real world into the programming, Object oriented programming relies on four important concepts.

  1. Inheritance
  2. Encapsulation
  3. Abstraction
  4. Polymorphism

Next: Inheritance in Object oriented Programming

Related Reading

Introduction to Object Oriented Programming – Part 2

Srinivas Reddy

Srinivas Reddy

An IT - Specialist with loads of experience in Java, J2ee platforms and loves to share his experience on technology with You...

More Posts - Website

Follow Me:

Related Posts

Srinivas Reddy
Written By:

An IT - Specialist with loads of experience in Java, J2ee platforms and loves to share his experience on technology with You...