Table of Content:
1) What exactly is OOPS?
2) List of Java OOPS Principles with Cases
What exactly is OOPS?
Object-Oriented Programming System (OOPs) is a programming paradigm based on the ideas of abstraction, encapsulation, inheritance, and polymorphism. It enables users to construct objects and methods to manipulate those items. The fundamental idea behind OOPs is to create objects, reuse them throughout the program, and modify these objects to get results.
OOP, which stands for "Object Oriented Programming," is a well-known and commonly utilized idea in current programming languages such as Java.
Download these Free EBooks:
1.
Source: Safalta
Introduction to digital marketing2. Website Planning and Creation
List of Java OOPS Principles with Cases:
Abstraction: Abstraction refers to the idea of concealing underlying intricacies and expressing things in simple words. Consider the addition of two numbers. The method's internal functioning is concealed from the outside world. In object-oriented programming, there are several methods for achieving abstraction, such as encapsulating and inherit. A Java application is another excellent example of abstraction. Java handles the conversion of simple instructions to machine code and conceals the deep implementation complexities from the outside world.
Classes and Objects: In an object-oriented system, objects are runtime entities. An object can refer to a person, a checking account, a location, or a data table. It may also express custom data types such as lists and vectors. Any programming challenge is examined using entities and how their communication with one another. When a program is performed, the objects communicate with one another by sending texts to one another. For illustration, the objects 'customer' and 'account' may send an email to the account object seeking the balance. Each object includes code and data that may be used to alter the data. Objects can even communicate with one another without understanding the specifics of their code or data. Using the class idea, the whole collection of code and information of an object may be converted to a user-defined data type. A class is a kind of data, and an object is a variable of that type. Following the creation of a class, any amount of objects can be produced.
A class is a group of items of similar sorts. Fruit items include, for example, cherry, banana, and pineapple. Classes function similarly to built-in data types in a programming language, but they are user-defined data types.
Example:
Class Home {
String address;
String color;
Double area;
Void openDoor() {
// write code here
}
Void closeDoor() {
// write code here
}
}
Encapsulation: Encapsulation is a method used in object-oriented programming to provide abstraction. Encapsulation is used to limit access to class members and functions. In object-oriented programming, accessibility modifier phrases are used to encapsulate data.
Public class Employ {
Private String name;
Public string getName() {
Return name;
}
Public void setName(String name) {
this.name = name;
}
Public static void main (String [] agrs) {
}
}
Polymorphism: Polymorphism is a key OOP concept; it refers to the ability to adopt multiple forms. For instance, an operation behaves differently under different conditions. The behavior is determined by the type of information utilized in the operation. For instance, the action of addition creates a sum for two integers. If the components are strings, the operation via concatenation yields the third string.
Objects with diverse internal structures can have the same external interface in polymorphism; this implies that a class of operation can be accessible in the same way even if the actions with each operation change. Polymorphism is a notion that is often used in inheritance.
Example:
class Polygon {
// method to render a shape
Public void render() {
System.out.println(“Rendering Polygon..”);
}
}
class Square extends Polygon {
// renders square
public void render() {
System.out.println(“Rendering Square…”);
}
}
class Circle extends Polygon {
// renders circle
Public void render() {
System.out.println(Rendering circle…“);
}
}
class Main {
Public static void main(String [] agrs) {
// create an object of Square
Square s1 = new Square();
S1.render();
// create an object of Circle
Circle c1 = new Circle();
c1.render();
}
}
Association: It is an OOPS concept that defines the relationship between objects. The multiplicity of items is defined by the relationship. Teachers and students, for example. A teacher and pupils have a one-to-many connection. A student might also have a one-to-many connection with instructor items. However, the student and instructor objects are distinct from one another.
Aggregation: All objects in this approach have their own lifespan. However, ownership exists, and a child object cannot belong to some other parent class. Consider the class/objects department and the teacher. A single teacher cannot belong to more than one department in this case, yet even if we eliminate the department, its teacher object is never deleted.
Object-oriented programming is a coding methodology and organisational structure that tries to solve some of the difficulties associated with traditional programming techniques by combining the greatest features of programming languages with a slew of new ideas. It comprises new ways of organising and constructing programmes and is unconcerned with the usage of a certain language. Languages that enable OOP features include Objective C, Java, and C++.