Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects". An object may contains:
- data: fields/attributes
- code: procedures/methods.
In OOP, computer programs are designed by making objects that interact with one another. An object can access and often modify the data fields of the object with which they are associated using their procedures.
This series will covers the basic concepts of OOP in Java and the association between objects.
Tutorials in this series:
Object-Oriented Programming ConceptsCore OOP (Object-Oriented Programming) concepts: inheritance, polymorphism, encapsulation, and abstraction. And object relation concepts: association, aggregation, and composition
OOP Concepts in JavaIntroduction to OOP concepts in Java programming language with examples. How to create a class and initiate an object from the class, also introduction to variables and methods in Java class.
Inheritance in JavaInheritance in Java with examples, which allows you to define a child class that inherits, extends, or modifies the behaviour of a parent class. How to use keywords: extends, final, and abstract in Java programming language.
Polymorphism in JavaHow Polymorphism works in Java with examples. In Java, we can perform polymorphism by method overloading and method overriding. And use final keyword to prevent sub-classes from overriding.
Encapsulation in JavaIn Java, encapsulation is done using access modifiers with classes, interfaces, setters, and getters. Java supports the following access modifiers: private, public, protected, and "default".
Abstraction in JavaAbstraction is a concept to handle complexity by hiding unnecessary details from the user. In Java, abstraction is achieved using abstract classes and interfaces. The difference between abstract class and interface, and how to use them, with example.
Abstract Class in JavaAn abstract class is a class that is declared abstract. It cannot be instantiated, but they can be sub-classed (extend). Learn how to create abstract class, and how abstract class work in Java, with example.
Interface in JavaIn Java, an interface is a reference type, similar to a class, that can contain only constants, method signatures, default methods, static methods, and nested types. Interface is used to achieve abstraction and multiple inheritance in Java.
Default and Static Methods in Java InterfacesBefore Java 8, interfaces could have only abstract methods and sub-classes must implements all it's abstract method. In Java 8 onward, we can create default and static methods in interfaces. Learn the benefits of these features, with example.
Private Methods in Java InterfacesPrivate methods in an interface is introduced Java 9. These private methods will improve code re-usability inside interfaces. For example, if two default methods in some parts have repetitive codes, they should move this part into a private method.
Abstract Class vs InterfaceWhen we need to use abstract class, and when to use interface? We must know the difference between the two. Abstract class is used to implement Template Method pattern, when interface is used (among others) to implement the Observer pattern.
Association, Aggregation, and Composition in JavaAssociation, Aggregation, and Composition in Java. Association is a relationship between two separate classes that establishes through their objects. Aggregation and Composition are subsets of association meaning they are specific cases of association.
Why We Use Class in Java?Classes help you take all the properties and behaviors of an object in your program, and combine them into a single template. In this article, we will try to understand why creating a well defined class is important for our application.