Object Oriented Programming in java

Object Oriented programming works on object instead of functions(like in 'c' language). Object Oriented development allows developers to think in terms of real time "things" or Objects, and simply solve issues with all those Objects.
Object is a real world entity.
For Example: Cat, Car, Ball are some of the examples of real world objects
An object represents two things

  • State - Dog has 4 legs , 1 tail , 2 ears. It shows the dog state
  • Behavior - are the functions or methods, that uses the state and shows behavior of an object

Principals of Object Oriented Programming in java :

  • Encapsulation - Binding "Data and Method" into a single unit. One of the ways to achieve good encapsulation is have your fields as private/protected and your methods as public. Example of Encapsulation is Human Brain, Capsule.

  • Abstraction Working on the essential things and to forget the things which are not essential.
    For Example : While using ATM machine you always need a ATM card and pin number. you doesn't involve how ATM machine works internally.

  • Inheritance Used to show parent - child relationship like one class inheriting the features of the other classes. It provides code reusablility if used wisely.

  • Polymorphism one thing having several forms.

For Example :
void add(int x,int y)
{
	System.out.println(x+y);
}
void add(float x,float y)
{
	System.out.println(x+y);
}
void add(int a,int b,int c)						
{
	System.out.println(a+b+c);
}
		
Encapsulation :

Binding "Data and Method" into a single unit. One of the ways to achieve good encapsulation is have your fields as private/protected and your methods as public. Example of Encapsulation is Human Brain, Capsule. For this reason, encapsulation is also referred to as data hiding.
Encapsulation can be described as a protective barrier that prevents the code and data being randomly accessed by other code defined outside the class. Access to the data and code is tightly controlled by an interface.
The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. With this feature Encapsulation gives maintainability, flexibility and extensibility to our code.

Abstraction :

Abstraction means working on the essential things and to forget the things which are not essential. Abstraction is separating the functions and properties that logically can be separated to a separate entity which the main type depends on.
Applying Abstraction during the design and domain modeling, helps a lot in design a system which is flexible and maintainable.