Skip to content Skip to sidebar Skip to footer

Oops

Java OOPs Concepts

  1. Object-Oriented Programming
  2. Advantage of OOPs over Procedure-oriented programming linguistic communication
  3. Difference between Object-oriented and Object-based programming language.

In this page, we will learn most the basics of OOPs. Object-Oriented Programming is a epitome that provides many concepts, such every bit inheritance, information binding, polymorphism, etc.

Simula is considered the first object-oriented programming linguistic communication. The programming paradigm where everything is represented equally an object is known as a truly object-oriented programming language.

Smalltalk is considered the first truly object-oriented programming language.

The popular object-oriented languages are Coffee, C#, PHP, Python, C++, etc.

The primary aim of object-oriented programming is to implement real-world entities, for instance, object, classes, abstraction, inheritance, polymorphism, etc.

OOPs (Object-Oriented Programming System)

Object means a real-world entity such as a pen, chair, tabular array, figurer, watch, etc. Object-Oriented Programming is a methodology or epitome to blueprint a program using classes and objects. It simplifies software evolution and maintenance by providing some concepts:

  • Object
  • Class
  • Inheritance
  • Polymorphism
  • Abstraction
  • Encapsulation

Apart from these concepts, there are some other terms which are used in Object-Oriented blueprint:

  • Coupling
  • Cohesion
  • Association
  • Aggregation
  • Limerick
Java OOPs Concepts

Object

Java Object

Whatever entity that has state and beliefs is known as an object. For example, a chair, pen, table, keyboard, cycle, etc. Information technology tin can exist physical or logical.

An Object can be defined every bit an instance of a class. An object contains an address and takes up some space in memory. Objects can communicate without knowing the details of each other'south information or code. The just necessary thing is the type of bulletin accustomed and the blazon of response returned by the objects.

Case: A dog is an object considering it has states like color, name, breed, etc. as well equally behaviors like wagging the tail, barking, eating, etc.

Class

Collection of objects is called form. It is a logical entity.

A class tin can also be defined as a blueprint from which y'all tin create an individual object. Class doesn't consume whatsoever space.

Inheritance

When one object acquires all the properties and behaviors of a parent object, it is known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.

Polymorphism in Java

Polymorphism

If one task is performed in different means, information technology is known every bit polymorphism. For case: to convince the customer differently, to depict something, for example, shape, triangle, rectangle, etc.

In Java, we apply method overloading and method overriding to achieve polymorphism.

Another example can be to speak something; for example, a cat speaks meow, dog barks woof, etc.

Abstraction

Hiding internal details and showing functionality is known equally abstraction. For example telephone call, nosotros don't know the internal processing.

In Java, we apply abstract course and interface to achieve abstraction.

Encapsulation in Java OOPs Concepts

Encapsulation

Binding (or wrapping) code and data together into a single unit are known as encapsulation. For example, a capsule, it is wrapped with unlike medicines.

A java class is the case of encapsulation. Coffee bean is the fully encapsulated grade considering all the data members are private here.

Coupling

Coupling refers to the knowledge or data or dependency of another class. It arises when classes are aware of each other. If a course has the details data of another grade, there is strong coupling. In Java, we apply individual, protected, and public modifiers to display the visibility level of a class, method, and field. You can utilize interfaces for the weaker coupling considering there is no concrete implementation.

Cohesion

Cohesion refers to the level of a component which performs a single well-divers task. A unmarried well-defined task is washed by a highly cohesive method. The weakly cohesive method volition carve up the task into divide parts. The java.io package is a highly cohesive package because it has I/O related classes and interface. Notwithstanding, the coffee.util parcel is a weakly cohesive package because it has unrelated classes and interfaces.

Association

Association represents the relationship betwixt the objects. Hither, one object tin be associated with 1 object or many objects. In that location tin be four types of association betwixt the objects:

  • One to 1
  • One to Many
  • Many to One, and
  • Many to Many

Let'south understand the relationship with real-fourth dimension examples. For instance, One country can have one prime number minister (one to i), and a prime minister tin can accept many ministers (one to many). Likewise, many MP'southward can have one prime minister (many to one), and many ministers can take many departments (many to many).

Clan can be undirectional or bidirectional.

Assemblage

Aggregation is a manner to achieve Association. Assemblage represents the relationship where 1 object contains other objects as a part of its state. It represents the weak relationship between objects. It is besides termed as a has-a relationship in Coffee. Like, inheritance represents the is-a human relationship. Information technology is another mode to reuse objects.

Composition

The composition is likewise a way to achieve Association. The limerick represents the human relationship where one object contains other objects equally a role of its state. At that place is a potent relationship between the containing object and the dependent object. It is the country where containing objects exercise not have an independent existence. If you delete the parent object, all the child objects will be deleted automatically.


Reward of OOPs over Procedure-oriented programming language

ane) OOPs makes development and maintenance easier, whereas, in a process-oriented programming language, it is not easy to manage if code grows every bit projection size increases.

2) OOPs provides data hiding, whereas, in a procedure-oriented programming linguistic communication, global data can be accessed from anywhere.

Global Data

Figure: Information Representation in Procedure-Oriented Programming


Object Data

Figure: Data Representation in Object-Oriented Programming

iii) OOPs provides the ability to simulate real-earth event much more effectively. Nosotros can provide the solution of real word problem if we are using the Object-Oriented Programming linguistic communication.


What is the difference between an object-oriented programming language and object-based programming language?

Object-based programming language follows all the features of OOPs except Inheritance. JavaScript and VBScript are examples of object-based programming languages.

Do You Know?
  • Can we overload the chief method?
  • A Coffee Constructor returns a value but, what?
  • Tin we create a program without main method?
  • What are the half dozen ways to use this keyword?
  • Why is multiple inheritance non supported in Java?
  • Why utilise aggregation?
  • Can we override the static method?
  • What is the covariant return type?
  • What are the iii usages of Java super keyword?
  • Why apply instance initializer block?
  • What is the usage of a blank final variable?
  • What is a marking or tagged interface?
  • What is runtime polymorphism or dynamic method dispatch?
  • What is the difference between static and dynamic binding?
  • How downcasting is possible in Java?
  • What is the purpose of a private constructor?
  • What is object cloning?
What will we learn in OOPs Concepts?
  • Advantage of OOPs
  • Naming Convention
  • Object and course
  • Method overloading
  • Constructor
  • static keyword
  • this keyword with six usage
  • Inheritance
  • Aggregation
  • Method Overriding
  • Covariant Return Type
  • super keyword
  • Instance Initializer block
  • final keyword
  • Abstruse class
  • Interface
  • Runtime Polymorphism
  • Static and Dynamic Binding
  • Downcasting with instanceof operator
  • Package
  • Access Modifiers
  • Encapsulation
  • Object Cloning

montenegrosualleadiang.blogspot.com

Source: https://www.javatpoint.com/java-oops-concepts

Post a Comment for "Oops"