Saturday, September 14, 2013

OOP concept in Java


Hi Guys !!! So this blog is all about the Object Oriented Programming  concepts . Lets start from the very basic concept of Object and Class .

What is an Object ?
Well It is the most basic concept and a key to understand the Object-Oriented programming . Object is an entity that has two characteristics ,  State and Behavior . Some examples of real world object can be : Bike , Chair , Dog etc. 

Lets take an example of a Bike . Bike has some state ( current gear , current speed ) and behavior ( change gear , apply brake ) . One way to begin thinking in an object-oriented way is to identify the state and behavior of real world objects .

Software objects are also similar to the real world objects. They too contains State and Behavior . An Object stores its state in  fields and exposes the behavior through methods.



What is Class ?
Class is a blueprint from which objects of same type can be created . Lets take an example of a Bike again . There are thousands of  bikes with the same characteristics i.e having same make and model . They are created from the same prototype / blueprint called class.


 Now we know the basics of an Object and  Class , so lets move on to Object Oriented principles
  • Inheritance 
  • Polymorphism
  • Abstraction 
  • Encapsulation


1. Inheritance :
Inheritance is the capability of one class to acquire the common state and behavior of   another class while adding its own functionality . In Object Oriented programming  , the concept of inheritance provides the idea of re-usability .  This means we can add additional features to a class without modifying it. 

How to achieve Inheritance in Java ?
extends keyword is used to inherit features of a class . 
class Parent {
// Parent has some state and behavior
}

class Child extends Parent {
// Inherit the common state and behavior of Parent class.
// Provide additional functionality.
}


2. Polymorphism :
Polymorphism means ability of one type to take more than one form . This can also be applied in Java where in sub-classes of a class can define their own unique behaviors and yet share some of the common functionalites of the parent class.

Example : 
Lets take an example of Bike . A company can produce different kind of bikes say , a mountain bike , and a roadbike . Now the two different types of bikes inherit the common features of a bike but also define their own separate features.

How to achieve Polymorphism in Java ? 
Overloading  and Overriding are the two ways to achieve Polymorphism.


3. Abstraction :
Abstraction is an essential element of Object Oriented programming . It refers to the act of presenting essential features without including the background details or explanations.

We can say that abstraction is purposeful suppression , hiding of some details of a process or artifact , in order to bring out more clearly other aspects , details or structures. Abstraction can be of control ( abstraction of actions ) or data . 

How to achieve Abstraction in Java ? 
Abstract classes and Interfaces are used to achieve Abstraction in Java.


4. Encapsulation :
Encapsulation is the binding of data and its associated functions in a single unit called Class . Access to the code and data inside the wrapper is tightly controlled through a well defined interface. Encapsulation provides a protective barrier that prevents the access of code and data from outside the class. 

The main benefit of encapsulation is the ability to re-factor the implemented code without breaking the code of others and thus provides flexibility and maintainability .




17 comments :

  1. Excellent Compilation of Question.

    Will be very helpful.

    Can you please add some question related to Filter ,Session management and Struts2?

    Thanks

    Arun

    ReplyDelete
  2. I liked your details very much. really good explanation. For every single details of java visit: java basic concepts

    ReplyDelete
  3. Nice explanation easy to understanding every concept. but i need some examples. Java Training Chennai

    ReplyDelete
  4. Java Training In Chennai

    Nice article i was really impressed by seeing this article, it was very interesting and it is very useful for me.I get a lot of great information from this blog. Thank you for your sharing this informative blog.

    ReplyDelete
  5. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    Greens Technologies In Chennai

    ReplyDelete

  6. Thanks for sharing amazing information about pega Gain the knowledge and hands-on experience you need to successfully design, build and deploy applications with pega. Pega Training in Chennai

    ReplyDelete

  7. Thanks for sharing amazing information about pega Gain the knowledge and hands-on experience you need to successfully design, build and deploy applications with pega. Pega Training in Chennai

    ReplyDelete

  8. hai you have to learned to lot of information about c# .net Gain the knowledge and hands-on experience you need to successfully design, build and deploy applications with c#.net.
    C-Net-training-in-chennai

    ReplyDelete

  9. hai you have to learned to lot of information about c# .net Gain the knowledge and hands-on experience you need to successfully design, build and deploy applications with c#.net.
    C-Net-training-in-chennai

    ReplyDelete
  10. Great post and informative blog.it was awesome to read, thanks for sharing this great content to my vision.
    scrum master Training in Chennai

    ReplyDelete
  11. BHEL Bhopal Apprentice Recruitment 2016



    thanks for sharing the useful article very helpful .........

    ReplyDelete
  12. Jharkhand Labour Department Recruitment 2016


    It’s amazing how interesting it is, My first visit made me very happy, Thanks to author..............

    ReplyDelete