Saturday, February 6, 2016

OOP Concept

Object Oriented Programming (OOP) is the core of Java programming. All Java programs are objects. Therefore, you have to know the basic concepts contained in OOP. Some characteristics of OOP are abstraction, encapsulation, inheritance, and polymorphism.

Abstraction


Abstraction is hiding complexity of the process. For example, people do not need to think that the car is a collection of tens or thousands of small parts (engine, wires, bolts, wheels, brakes, etc.). People only need to think that a car is an object that already has a specific behavior, which can be used as a means of transportation, so they only have to know how to use it or drive it without having to know the complexity of processes contained in the car. This means, the car maker has hidden all the complexities of processes contained in the car and the user does not need to know how the system of the engine, transmission, and brake work. This concept is called abstraction.

Example of abstract in OOP model: we as programmers do not need to know in detail how to create a button. We just need to know how to use an existing button object (data/property or method). In this case, the creator of the object has been abstracted all processes related to the creation of a button.

Encapsulation


In the program code, the process of abstraction which we have mentioned above can be done by wrapping all the code and data pertaining to one single entity, called object. In other words, the packing process itself is a mechanism for abstraction. In traditional programming, this process is often called information hiding. By doing the packing code and data in Java, there are three access levels called access modifiers: private, protected, and public.

  • Private Access Modifier

    By declaring data and method using private access modifier, then data and method can only be accessed by class itself. This means that data and method can not be accessed or used by other classes contained in the program. To declare data and method with private access level, use the keyword private.

  • Protected Access Modifier

    A data or methods that are declared with protected access modifier can be accessed by class itself and also by classes that still have child relationship. For example, if the data x in the class A declared as protected, then class B, which is derived from class A, can access the data x. But, if there are other classes, such as class C that is not derived from class A and B, class C can not access the data x. To declare data and method with protected access level, use the keyword protected.

  • Public Access Modifier

    Public access modifier is the opposite of private access modifier. Data and methods that are declared with public can be accessed by all sections in the program. In other words, Data and methods that are declared by public access modifier will be recognized and can be accessed by all classes in the program, Either derived classes or classes that do not have a relationship at all. To declare data and methods with public access level, use the keyword public.

Inheritance


OOP model also apply inheritance concept, as well as in real life. For example, a child would have inherited some traits or behaviors that are owned by his/her mother/father. Likewise, in a program, a class can be derived into other new classes that will inherit some of the properties or the behavior of its parent class.

For example, if we have a class A in a program we created, then we can create derived classes from class A (eg, class B) who inherits the properties contained in the class A. This is called inheritance. In the Java terminology, the parent class is called the superclass and the derived class is called the subclass.

Polymorphism


Polymorphism is the ability of an object to reveal a lot of things through the same way. For example, there is a class A which was derived to class B, C, and D. With polymorphism concept, we can run those methods contained in classes B, C, and D only from the object instantiated with class A. Polymorphism is often called with dynamic binding, late binding, or runtime binding.

8 comments:

  1. Thank you for sharing valuable information with us.

    Java web application is a type of free programming language used to develop applications and software that are becoming highly in demand on the internet. The software engineer can provide the web application or software in the form of windows, Linux, and MAC OS. There are various types of systems that can not work without java and it is getting necessary day by day even the world’s no.1 application depends on java. Java has become a most popular feature in android smartphone applications that's why Aptech learning provides java training in Dwarka, Janakpuri, and in Gurgaon also. Java training helps to get you complete knowledge about web frameworks, Java testing tools, and design patterns in java.

    Let's get learn about the PHP training course
    PHP is a type of programming language that is most commonly used in dynamic functions such as modifying, collecting, and deleting all types of databases It also helps to encrypt all types of data in the form of HTML and XML file. Aptech learning provides you with a complete PHP training course at a reasonable cost that will help you to grow more in the era of the software industry.

    For more details please visit our website : Aptech Janakpuri

    ReplyDelete