Java Tutorial 1: Introduction to object oriented programming

Hi My name is Jasleen and I am gonna explain to you what exactly is object oriented programming in the most layman language possible. So what exactly is OBJECT ORIENTED PROGRAMMING? Sounds daunting right? But once you understand it you will realize it is NOT. You will discover its potential and it will change your perception towards how you see programming.

In object oriented programming we have only one job- Design Objects and put them into code. You must be thinking this girl is nuts and doesn't know anything. I am wasting my time. Trust me you are not.



Lets us first understand what exactly is an object and in posts to come we will explore the full depth of object oriented programming. An object can be anything from a bag to ball, an apple, a list, etc. Virtually anything you see around you is an object and yes in programming too we are gonna design objects just like they are real world entities.


Just imagine the software you are designing is your personal world and you are its creator. Its on you how all the objects will be. Roughly speaking each real world object has the following properties: -

  • They have some attributes- a shape, height ,weight, etc.
  • They have some function- decoration, carrying stuff, etc.
Some objects have other properties too. They are a kind of some other kind of object(Example:  BMV is a car). Some objects interact with other objects(A knife cuts an apple ). Some objects work together  and others work individually. 

Similarly an object in any programming language is an entity which has some attributes and some functions. The attributes form the data and functions define its behavior.

But how do we define an object??? How do we tell the program that the object will have what attributes and what functions.

Enter classes. A class is a form of a blueprint or a stencil for an object. A class is like a factory that produces objects. 

You must be thinking why do we need a class to produce an object? The answer is very simple to decrease the amount of code and promote re-usability. 

Still not clear?? You see we have so many objects around us. And some of the objects are same in nature. We dont have only one apple, we dont have only one bag. We have so many objects of same kind. You, me your sister, mother are all objects of the kind HUMAN. We all have same features and same kind of attributes. Note that i said "Kind of attributes" not "same attributes". You and i  both have 2 eyes but my eyes are different than yours.


Ok you must be thinking how does creating a class decrease my amount of code??? Using a blueprint for an object, we can create multiple objects of same kind, set their respective data and we are good to go. This might sound confusing. Suppose you are designing an employee management system. And you need to enter data of all the employees  in the system. All the employees will have a name, a position, salary, etc. So you will need to set this structure only once. After we have designed the structure, we can just create objects using that structure without any significant amount of coding. Each object will represent one employee. SO in this context a class is an employee producing factory and objects are its produce.



We saved time, effort and our code was reused.(Concept of re-usability will be more clear in tutorials about to come. Stay tuned!!)

So i hope you are clear on the notion of class and object and why both of them are important. If there is any doubt leave a comment below and if you liked my tutorial subscribe.


1 comments:

garlanahsabia said...

Stainless Steel Poker Chips - Titanium Art
Stainless steel poker chips are designed with a unique and premium steel titanium tent stakes style to titanium banger improve titanium tube their grip and to provide a more aggressive grip. The thickness and the thickness of rainbow titanium the titanium astroneer