Home Java Docker
Home     Java

Java Topic

What is Java
History of Java
Freature of Java
Difference Between Java & C++
Java Environment Set Up
Java Hello World Program & its Internal Process
Java Hello World Program
JDK, JRE and JVM
Java Variables
Java Data Types & Unicode System
Java Operators
Java Keywords
Java Control Statements
Java if else
Java switch
Java for loop
Java While loop
Java Do While loop
Java break
Java continue
Java Oops Concept
Java Object & Class
Java Method
Java Constructor
Java Static Keyword
Java this Keyword
Java Inheritance
Java Hybrid Inheritance
Aggregation(HAS-A)
Java Polymorphism
Java method overloading
Java method overriding
Java Runtime polymorphism
Java Dynamic Binding
Super keyword
Final keyword
Difference Between method overloading and method overriding
Java Abstraction
Java Interface
Abstract class vs Interface
Java Encapsulation
Java Package
Java Access Modifiers
covariant return type
Instance initializer block
Java instanceof operator
Object Cloning in Java
Wrapper classes in Java
Java Strictfp Keyword
Recursion in Java
Java Command Line Arguments
Difference between object and class
Java String
Java String Class
Java Immutable String
Java Immutable Class
String Buffer
String Builder
String Buffer vs String
String Builder vs String Buffer
String Tokenizer in Java
Java Array
Java Exceptions Handling
Java Try-Catch block
Java Multiply Catch Block
Java Finally Block
Java Throws Keyword
Java Throw Keyword
Java Exception Propagation
Java Throw vs Throws
Final vs Finally vs Finalize
Exception Handling With Method Overridding
Java Multithreading
Lifecycle and States of a Thread in Java
How to create a thread in Java
Thread Scheduler in Java
Sleeping a thread in Java
Calling run() method
Joining a thread in Java
Naming a thread in Java
Thread Priority
Daemon Thread
Thread Pool
Thread Group
Shutdown hook
Multitasking vs Multithreading
Garbage Collection
RunTime Class
Java Synchronization
Synchronized block in Java
Static Synchronization in Java
Deadlock in Java
Inter Thread Communication in Java
Interrupting Thread in Java
Reentrant Monitor in Java
Java Applet
Animation in Applet
EventHandling in Applet
Display image in Applet
Displaying Graphics in Applet
Parameter in Applet
Java 8 Features
Java Lambda Expressions
Method References
Functional Interfaces
Java 8 Stream
Base64 Encode Decode
Default Method
for Each() Method
Collectors class
String Joiner Class
Optional Class
JavaScript Nashron
Parallel Array Sort
Type Interface
Parameter Reflection
Type and Repeating Annotations
JDBC Improvements

Java OOPs Concepts

    We will learn about the fundamentals of OOPs on this page. The paradigm of object-oriented programming offers several ideas, including polymorphism, inheritance, and data binding.

    Object-Oriented Programming, or OOPs, refers to programming languages that employ objects as a key source for implementing what is to happen in the code. The user or viewer see objects as they execute the tasks assigned to them. They apply real-world principles such as inheritance, encapsulation, polymorphism, and other relevant concepts. in programming is the goal of object-oriented programming.



Table Of Content

  • Java OOPs Concepts
  • OOPS concepts
  • Pillars of OOPs
  • Difference Between Object-Oriented and Procedure Programming languages





    OOP's primary goal is to bind together the data and the method that use them so that only that function and no other part of the code can access the data. The first programming language that was genuinely object-oriented is smalltalk.


Object-Oriented Programming Concepts are as follows:

1. Class

2. Object

3. Method

4. Pillars of OOPs

  • Inheritance
  • Polymorphism
    • Compile-time polymorphism
    • Runtime polymorphism
  • Abstraction
  • Encapsulation




In addition to these concepts, there are a few other terms used in Object-Oriented design:

1. Association

2. Aggregation

3. Cohesion

4. Coupling

5. Composition




Object-Oriented Programming Concepts


Class:

  • In object-oriented programming (OOPs), Classes serves as a tailored blueprint, a precise model used for creating object A class is essentially a blueprint or template that defines the properties and behaviors of objects. OOP classes lassencapsulates both data (in the form of variables) and methods that operate on that data.
  • In general, class declarations can contain the following parts :



  • Class name:we should declare class name when defining class.By convention, the class name should begin with the first letter capitalised.
  • access modifier :A class may be public or have default access as a modifier .
  • Superclass (if needed): If there is one, the term extends is followed by the name of the superclass. Only one parent can be extended (subclassed) by a class.
  • Interfaces (if needed): A list, separated by commas, of the interfaces that the class, if any, implements. A class may support several interfaces.
  • Body :Code inside the class body is surrounded by braces {}



Class structure




Object :

  • A fundamental building block of object-oriented programming, an object represents actual physical entities. Many objects are created by a normal Java programme, and as you are aware, these objects interact via calling methods
  • The parts of your code that are visible to the viewer or user are the objects, which carry out your code
  • In general, object declarations can contain the following parts :
  • State:: An object's properties serve as a representation of it. Additionally, it reflects an object's characteristics.
  • Behavior :An object's methods act as a representation of behaviour. Additionally, it demonstrates how one object responds to others.
  • Identity :An object's identity is its special name, which enables it to communicate with other things.
  • Method :A method is a group of statements that work together to complete a certain job and provide the outcome to the calling. A method can operate with no output. Since we can reuse the code with methods instead of having to type it all over again, they are regarded as time savers. In contrast to languages like C, C++, and Python,
    Java requires that every method be a component of a class.



Object structure

 // Java  program using class and object   
public class Student{
    static String Student_name;
    static int Student_id;
 
    static void set(String name, int id) {
    	Student_name  = name;
    	Student_id  = id;
    }
 
    static void get() {
        System.out.println("Student name is: " +Student_name );
        System.out.println("Student id is: " + Student_id);
    }
 
    public static void main(String args[]) {
    	Student.set("Dr Alok Raja", 1403195);
        Student.get();
    }
}



Output:

Student name is: Dr Alok Raja 
Student id is:14031952 

Pillars of Object-Oriented Programming

Inheritance :

  • Inheritance occurs when one object inherits all of the properties and behaviours of a parent object. It allows for code reuse. It is employed in order to achieve runtime polymorphism.
  • Object-Oriented Programming (OOP) heavily relies on inheritance. In Java, inheritance is the mechanism that enables one class to inherit the features (fields and methods) of another class.
  • Inheritance promotes the concept of "reusability," where we can create a new class by deriving it from an existing class that already contains some of the code we need. This allows us to use the existing class's fields and methods, encouraging code reuse.
  • Superclass:: The class whose characteristics are inherited is referred to as the superclass (also known as base or parent class).
  • Subclass :The class that inherits the other class is referred to as a subclass (also known as derived or extended or child class). In addition to the superclass's fields and methods, the subclass can add its own.



Polymorphism :

  • Polymorphism used when one task is performed in multiple ways. To persuade a customer to change their mind, for example, draw a shape, triangle, rectangle, etc.
  • To achieve polymorphism in Java, we use method overloading and method overriding.
  • Polymorphism is the ability of object-oriented programming languages to efficiently differentiate between entities sharing the same name. In Java, this is achieved by utilizing the unique signatures and declarations of these entities.




Abstraction :

  • Abstraction is the method of hiding internal information while displaying functionality.
  • The capability of data abstraction allows the user to only see the most important information. Simple or unnecessary units are not displayed to the user.
    Ex: A computer is regarded as a whole rather than as its component parts.

Encapsulation :

  • Encapsulation is the process of binding (or wrapping) code and data into a single unit.
  • It is defined as the consolidation of data into a single unit. It is the mechanism that connects the code and the data that it manipulates. Encapsulation can also be thought of as a protective shield that prevents code from accessing data outside of the shield.



  • Because all of the data members are private in this class, Java Bean is the fully encapsulated class.
  • Because all of the data members are private in this class, Java Bean is the fully encapsulated class.
  • Encapsulation can be accomplished by writing public methods in the class to set and get the values of the variables and by declaring all of the variables in the class as private.

Association

  • The relationship between the things is represented through association. In this case, one object can be associated with one or more objects. There are four possible types of relationship between the things.
  • One to One
  • One to Many
  • Many to One
  • Many to Many

Aggregation

  • Aggregation is a method of achieving Association. Aggregation denotes the relationship in which one thing includes other objects as part of its state. It symbolises the weak connection between objects. In Java, this is known as a has-a connection. For example, the is-a relationship is represented by inheritance. It is another another method of reusing items.




Cohesion

  • The level of cohesion of a component that performs a single well-defined task. A highly cohesive method completes a single well-defined task. The task will be divided into sections using the weakly cohesive method. Because it contains I/O-related classes and interfaces, the java.io package is highly cohesive. The java.util package, on the other hand, is a weakly cohesive package because it contains unrelated classes and interfaces.

Coupling

  • The knowledge, information, or dependency of another class is referred to as coupling. It occurs when classes are aware of one another. There is strong coupling when one class has the details information of another class. To display the visibility level of a class, method, or field in Java, we use the private, protected, and public modifiers. Because there is no concrete implementation, you can use interfaces for the weaker coupling.

Composition

  • Association can also be accomplished through composition. The composition denotes a relationship in which one object contains other objects as part of its state. The containing object and the dependent object are inextricably linked. It is the condition in which containing objects do not exist independently. When you delete the parent object, all of the child objects are also deleted.



Comparison Chart

Difference Between Object-Oriented and Procedure Programming languages are mention below


S.N Procedural Programming Object-Oriented Programming
1. A programming paradigm known as procedural programming centres the program's structure around procedures or functions. It separates the programme into smaller modules or functions and focuses on providing step-by-step instructions to solve a problem. The basic concept of the object-oriented programming (OOP) is the interaction of objects.The division of data and tasks into reusable "objects" that can communicate and share resources is highlighted.
2. The focus of procedural programming is on breaking down the issue into a series of steps or procedures. It follow Top-down approach, the main programme calling various functions to carry out the desired task. The focus of object-oriented programming(OOP) is to making objects that can interact and work together to solve problems by encapsulating data and methods. OOP follow a bottom-up methodology in which objects are created and modified to produce the desired results.
3. Procedural programming is insecure compared to object-oriented programming(OOPs). Object-oriented programming(OOPs) uses abstraction to achieve data hiding. As a result, it provides greater security than procedural programming.
4. Procedural programming organizes data and code into separate functions or modules. Data is typically stored in global variables, accessible by multiple function i.e Data moves freely within the system from one function to another function in procedural programming. Object-oriented programming organizes data and code into classes and objects. Data is encapsulated within objects, and functions associated with objects are called methods. Objects can interact with each other through method invocations and exchange data using member variables.
5. There are no access modifiers in procedural programming, private, public, and protected are access modifiers in Object-oriented programming(Oops)
6. Code reusability in procedural programming is achieved buy use of functions. Functions can be called from different parts of the program, allowing code to be reused. Object-oriented programming promotes code reusability using the concept of inheritance. Classes can inherit properties and behaviors from other classes.In this way code is reused.
7. Method Overloading is not possible in procedural programming language. Method overloading or method overriding is possible in Object-oriented programming
8. No concept of Abstraction(Data Hiding) or Inheritance in procedural programming. The Abstraction(Data Hiding) or Inheritance are main pillar of O bject-oriented programming.
9. In procedural programming, error handling is typically done through error codes or return values. In object-oriented programming, exceptions are mainly used to handle errors, it make code more robust to handle error.
10. C, Fortran, Pascal, and Visual Basic are all examples of procedural programming. Object-oriented programming examples include:.NET, C#, Python, Java, VB.NET, and C++.
Java Object & Class Next »
« Perv Next »


Post your comment





Read Next Topic
Java Tutorial - Topic
Java Oops Concept
Java Object & Class
Java Method
Java Constructor
Java Static Keyword
Java this Keyword
Read Other Java Chapter
Java Topic
Java Basic Tutorial
Java Control Statements
Java Classes & Object
Java Inheritance
Java Polymorphism
Java Abstraction
Java Encapsulation
Java OOPs Miscellaneous
Java Array
Java String
Java Exception Handling
Java Multithreading
Java Synchronization
Java Applet
Java 8 Features
Java 9 Features
Java Collection
Java Mcq
Java Interview Question
Tools
  

Useful Links

  • Home
  • Blog
  • About us
  • Contact Us
  • Privacy policy

Contact Us

Police Colony
Patna, Bihar
India

Email:

About DockerTpoint


India's largest site for Programming Tutorial as well as BANK, SSC, RAILWAY exam
and Campus placement preparation.