Core Java Tutorial 09 – Introduction to Object Oriented Programming ( Classes and Objects in Java)

In this video tutorial, we will go through an introduction to Object Oriented programming concepts. We will learn the concept of a Class and an Object in an Object Oriented world by taking help of real life analogy.

For our readers who are unable to access the Video Tutorial!!!

This tutorial will take you through the concept of a Class and an Object in a Java program.

Java is an Object Oriented Programming language- which means the programs we write using Java always follow the Object Oriented concepts or guidelines.

A Program is  a set of instructions which does some task for eg : sending an email to your friend, addition of two numbers etc. In real life projects, you will be asked to write a software which may involve many functions in a single software like a GMAIL application. A single Gmail application is capable of sending an email to any of your friend, receiving an email from your friend, maintaining a list of your known contacts, chat program which you use to send an instant message to your friend etc . There can be many approaches for writing a program where a program can be as big as a program like GMAIL or a simple program performing just addition of two numbers and Object Oriented is one of such approaches. What it is says,

A software system should always be looked or written as a combination of many individual small programs called as Objects which will interact with each other to form a bigger software or a program.

Let us understand the concept by taking a simple example of say building a kitchen- for building a kitchen we  will bring individual objects from market say a microwave, spoons, knife, refrigerator, and  some other useful utensils etc to form a kitchen. In your kitchen, in addition to having objects of different types, you also have some objects which are of same type for example: many spoons.  ( different shapes and sizes ). Here, the point to note is:  each object in your kitchen is capable of Performing some task, represents a STATE and has a Real Time Existence in your kitchen.

The most important thing to know about an Object is :

  • Object is capable of performing some task
  • It represents a State (e.g : a microwave can be in ON or OFF  state , a refrigerator is in grey color state etc)
  • It has a real time existence ( means it occupies some space in your kitchen and you can feel it’s presence )

One object may use another object for carrying out a certain task e.g in order to prepare a vegetable dish, a person object uses a knife object for cutting purpose and then uses a bowl object along with a microwave object for cooking it and in the end uses many plate and spoon objects for serving purpose.

To summarize the above content: an Object in a real life has the Capability to perform a certain Task, represents a State and has a Real Time Existence. In a much similar way, a Program or a Software that you write is made up of many small programs where each such small program is called as an object. You may have many different or same type of objects in your application and just like how an object in real life behaves; each object in terms of a program too represents some state, has a real time existence and is capable of performing a certain task. When you run the application, one or many objects in your application together will perform a certain task.

Now the question arises –Where object comes from ??? the answer is quite simple – someone creates them. Before creating any object you always need to write a blueprint for the actual object e.g for creating a spoon object in a factory you will first need to write the blueprint or a complete description of the required spoon object and its only then by reading through this description: a factory guy would manufacture the actual spoon object. Its a one time activity, writing the blueprint of what you want in an actual object and later on you may go on creating any number of physical objects of that type.

 Important point to note that the blueprint is just the complete description of an object but not the actual object.

Similarly, in a software application, we will need to write a blueprint of how a specific object looks like and what task it is capable of performing. This blueprint is called as a CLASS. Once a class is ready you go on creating any number of objects of that type by reading through the class specification.

In this tutorial, we just tried to  show you the approach for writing a program based on Object Oriented Programming Concepts which is exactly similar in the way how real world works.

Happy Learning!!!