Concepts de base Java OOps

OOP concepts allow us to create specific interactions between Java objects. They make it possible to reuse code without creating security risks or making a Java program less readable. Here are the four main principles in more detail. Abstraction Abstraction aims to hide complexity from the users and show them only the relevant information. For example, if you want to drive a car, you don't need to know about its internal workings. The same is true of Java classes. You can hide internal implementation details by using abstract classes or interfaces. On the abstract level, you only need to define the method signatures (name and parameter list) and let each class implement them in their own way. Abstraction in Java: Hides the underlying complexity of data Helps avoid repetitive code Presents only the signature of internal functionality Gives flexibility to programmers to change the implementation of the abstract behaviour Partial abstraction (0–100%) can be achieved with abstract classes Total abstraction (100%) can be achieved with interfaces

Encapsulation Encapsulation allows us to protect the data stored in a class from system-wide access. As its name suggests, it safeguards the internal contents of a class like a real-life capsule. You can implement encapsulation in Java by keeping the fields (class variables) private and providing public getter and setter methods to each of them. Java Beans are examples of fully encapsulated classes. Encapsulation in Java: Restricts direct access to data members (fields) of a class. Fields are set to private Each field has a getter and setter method Getter methods return the field Setter methods let us change the value of the field

Polymorphism Polymorphismrefers to the ability to perform a certain action in different ways. In Java, polymorphism can take two forms: method overloading and method overriding. Method overloading happens when various methods with the same name are present in a class. When they are called they are differentiated by the number, order, and types of their parameters. Method overriding occurs when the child class overrides a method of its parent. Polymorphism in Java: The same method name is used several times. Different methods of the same name can be called from the object. All Java objects can be considered polymorphic (at the minimum, they are of their own type and instances of the Object class). Example of static polymorphism in Java is method overloading. Example of dynamic polymorphism in Java is method overriding.

Inheritance Inheritance makes it possible to create a child class that inherits the fields and methods of the parent class. The child class can override the values and methods of the parent class, however it's not necessary. It can also add new data and functionality to its parent. Parent classes are also called superclasses or base classes, while child classes are known as subclasses or derived classes as well. Java uses the extends keyword to implement the principle of inheritance in code. Inheritance in Java: A class (child class) can extend another class (parent class) by inheriting its features. Implements the DRY (Don't Repeat Yourself) programming principle. Improves code reusability. Multilevel inheritance is allowed in Java (a child class can have its own child class as well). Multiple inheritances are not allowed in Java (a class can't extend more than one class).

Association Besides the four main principles of OOP, Java also works with three further concepts (association, aggregation, composition) you can make use of when designing your programs. Aggregation is a special form of association, while composition is a special form of aggregation. Association simply means the act of establishing a relationship between two unrelated classes. For example, when you declare two fields of different types (e.g. Car and Bicycle) within the same class and make them interact with each other, you have performed association.Learn more advance concepts from the Java training institute in chennai. Association in Java: Two separate classes are associated through their objects. The two classes are unrelated, each can exist without the other one. Can be a one-to-one, one-to-many, many-to-one, or many-to-many relationship.

Recommended Posts

Concepts de base Java OOps
Grammaire de base Java
Grammaire Java de base
Connaissances de base Java 1
[Java] Structure de base
[Java] [Basic] Glossaire
Grammaire de base Java
Grammaire de base Java
Exercice Java [basique]
mémo de connaissances de base java
[Java] Type de données ①-Type de base
Manipulation de base de la date Java
Conventions de dénomination Java de base
Mémo d'apprentissage Java (basique)
[Java] Notes de méthode de base
Types de données de base Java
Authentification de base avec Java 11 HttpClient
Syntaxe de base Java + trappe α
[Java] Instruction de base pour les débutants
[Java] Thymeleaf Basic (Spring Boot)
Implémenter l'authentification de base en Java
Contenu d'apprentissage de base Java 8 (API Java)
[Débutant] Description du "tableau" de base Java
Contenu d'apprentissage de base Java 4 (répétition)
[Java] Termes de base en programmation
[Java] Types de base et notes d'instructions
Contenu d'apprentissage de base Java 3 (opérateur / opérateur ternaire)
Types de données de base et types de référence (Java)
Contenu d'apprentissage de base Java 9 (expression lambda)
Utilisation de base de Java Facultatif Partie 1
Contenu d'apprentissage de base Java 2 (array / ArrayList)
Flux de traitement de base de Java Stream
Types de données de base et types de référence Java
[Connaissance de base de Java] Portée des variables
Structure de base du code source Java
Profilage avec Java Visual VM ~ Utilisation de base ~
Méthode de concurrence en Java avec exemple de base
[Java] Résumé personnel des instructions conditionnelles (basique)
Connaissance de base de la rédaction de notes de développement Java
[Note] Coopération entre Java et DB (basique)
[Java] J'ai personnellement résumé la grammaire de base.
Étudier Java (examen d'ingénieur en informatique de base)
[Connaissance de base de Java] À propos de la conversion de type
Contenu d'apprentissage de base Java 1 (littéral, variable, constant)
Grammaire Java de base à connaître en premier
Implémentation d'un algorithme de recherche / tri de base en Java