Basic Java Knowledge.

Even the king of Java had to read to understand what OOP really means.

As the name suggests, > Object-Oriented Programming
or OOPs refers to languages that use objects in programming, they use objects as a primary source to implement what is to ha…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Kelechi Divine

Even the king of Java had to read to understand what OOP really means.

As the name suggests, > Object-Oriented Programming
or OOPs refers to languages that use objects in programming, they use objects as a primary source to implement what is to happen in the code. Objects are seen by the viewer or user, performing tasks assigned by you. Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism etc. in programming. The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function. I believe you understand how to declare a method in Java and have a full understanding of the types of methods that Java has.

For example, a dog is an object because it has states like colour, name, breed, etc. as well as behaviours like wagging the tail, barking, eating, etc.

Concepts of Object Oriented Programming

  1. Class: The collection of objects is called class. It is a logical entity. A class can also be defined as a blueprint from which you can create an individual object. “Class doesn’t consume any space”.
public class Practice {

}
  1. Inheritance: When one object acquires all the properties and behaviours of a parent object, it is known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism. For example, Nigeria is a Parent Object; Lagos, Imo and Ogun states are all inheriting from the parent object.

  2. Polymorphism: If one task is performed in different ways, it is known as polymorphism. In Java, we use method overloading and method overriding to achieve polymorphism.

public class Animal {

    private String name;

    private String color;

    private int age;

    public Animal(String name, String color, int age){
       this.name = name;
       this.color = color;
       this.age = age;
    }

    public Animal(String name, int age){
       this.name = name;
       this.age = age;
    }

  1. Abstraction: Hiding internal details and showing functionality is known as abstraction. In Java, we use abstract class and interface to achieve abstraction.
public abstract class Animal {

   private Heart heart;

   private Lungs lungs;

   private Kidney kidney;

  1. Encapsulation: Binding (or wrapping) code and data together into a single unit are known as encapsulation. For example, a capsule is wrapped with different medicines. A java class is an example of encapsulation. Java bean is the fully encapsulated class because all the data members are private here.

  2. Coupling: Coupling refers to the knowledge or information or dependency of another class. It arises when classes are aware of each other. If a class has the details information of another class, there is strong coupling. In Java, we use private, protected, and public modifiers to display the visibility level of a class, method, and field. You can use interfaces for the weaker coupling because there is no concrete implementation.

Image description

You can also view my medium account here

Thank you for reading and I hope you learned something. zip it now!


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Kelechi Divine


Print Share Comment Cite Upload Translate Updates
APA

Kelechi Divine | Sciencx (2022-10-05T23:29:03+00:00) Basic Java Knowledge.. Retrieved from https://www.scien.cx/2022/10/05/basic-java-knowledge/

MLA
" » Basic Java Knowledge.." Kelechi Divine | Sciencx - Wednesday October 5, 2022, https://www.scien.cx/2022/10/05/basic-java-knowledge/
HARVARD
Kelechi Divine | Sciencx Wednesday October 5, 2022 » Basic Java Knowledge.., viewed ,<https://www.scien.cx/2022/10/05/basic-java-knowledge/>
VANCOUVER
Kelechi Divine | Sciencx - » Basic Java Knowledge.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/10/05/basic-java-knowledge/
CHICAGO
" » Basic Java Knowledge.." Kelechi Divine | Sciencx - Accessed . https://www.scien.cx/2022/10/05/basic-java-knowledge/
IEEE
" » Basic Java Knowledge.." Kelechi Divine | Sciencx [Online]. Available: https://www.scien.cx/2022/10/05/basic-java-knowledge/. [Accessed: ]
rf:citation
» Basic Java Knowledge. | Kelechi Divine | Sciencx | https://www.scien.cx/2022/10/05/basic-java-knowledge/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.