Friday, March 3, 2017

Fundamentals of Object Oriented Programming in Java

I remember when I was doing my engineering, the OOPS concept was in the first semester. Back then it looks like some alien things to me, because I have never done programming and even the smallest program we get to write e.g. checking whether the number is palindrome or not, or printing the Fibonacci series, we never really needed to use OOPS. When needed, I just memorize things and written down in exam :). That worked, I passed the exam but effectively I didn't learn OOP or Object Oriented Programming on those days.

It's when I started learning java (an almost truly object-oriented programming language) and introduced to concepts like abstract classes, interface, and method overriding; something started to go in my mind.

This blog post is very basic in nature, but I really hope it could help beginners in understanding things like class, object, abstraction, polymorphism, inheritanceencapsulation, composition, cohesion, coupling, interface programming, etc.

Btw, if you are new into the world of object-oriented programming and design then I also suggest you go through a hands-on course like UML and Object-Oriented Design Foundations by Karloy Neisztor on Udemy. It's a great course to understand the complete process of object-oriented analysis and design for creating quality software.

What is Object-Oriented Programming

What is object oriented programming in JavaI am planning to write a clear and concise post on each of these because I really don't like too much information in one shot. It never worked with me, I believe learning is a gradual process and always starts with the most simple things, which eventually turned out to be the most important one.

So What is Object Oriented programming?
Simple programming which is oriented on objects :) means treat everything surrounding you as an

Now the question comes, what is Object?
An Object is a particular concrete instance of Class, and what is the class? A Class is a blueprint from
which object gets created which has attributes and behavior, we call attributes as members and behavior as methods.

lets see one example : how about representing a classroom using OOPS?
A classroom is a room , which has certain no of chairs , desks , blackboard , teacher , students etc.

Now in order to represent that in code, we need to write a program. In Java we will write like this.

public class ClassRoom {

int noOfChairs;
int noOfDesks;
Teacher currentTeacher;
Students [] students;
Blackboard blackboard;

public int getNoOfChairs(){


public Teacher getNoOfTeacher(){




I have omitted most of the methods, just to focus on concept rather than implementation. So now we know that class is blueprint, which has member variable and methods and used to create object. Now what is object here, any classroom in which any lecture is going on , your first lecture would be one instance, second lecture would be another instance.

See the point, every object of same class has same no of variables but there value gets changed e.g. lecture 1 was attended by 15 students by teacher called Mr. Gupta , lecture 2 was attended by 18 students which was by Miss Amrita.

Any thing which you see around can be represented in class and object e.g. this blog is an instance of Blog class, a particular movie can be instance of Movie class e.g. Titanic is an instance of Movie where actor/director are different than other movie.

That's all on fundamentals of object oriented programming in Java. I hope you got the idea of representing real world things on class and objects, by doing this we try to create applications which solves real world problems. Visualizing and understanding in terms of object also makes programming easy to write, read and maintain.

Further Learning
SOLID Principles of Object Oriented Design
Absolute Introduction to Object Oriented Programming in Java
Java - Object Oriented Programming [For Absolute Beginners]

Related Java and OOPS programming tutorials.
Difference between static and dynamic binding
Difference between overloading and overriding 
How to run Java HelloWorld program from command line
How to find middle element of linked list in one pass
How to swap two numbers without using third variable


Anonymous said...

Explaining in easy and good way OOPS. Great Sir....

Unknown said...

The most simpler way of explaining OOP's concept I have ever seen

Unknown said...

where is the continuation of this OOPS?

Anonymous said...

Good explanation

Post a Comment