The Techie King


Java OOPs Concepts

In this article, we will learn about the basics of OOPs

Article By The Techie King

What is OOPs?

Object-Oriented Programming is a paradigm that provides many concepts, such as Inheritance, Abstraction, Polymorphism,Encapsulation etc.

The concept of "objects", which can contain data and code: data in the form of fields, and code, in the form of procedures. A feature of objects is that an object's own procedures can access and often modify the data fields of itself.


OOPs Concepts are as follows

  1. Class
  2. Object
  3. Method and method passing
  4. Pillars of OOPS
    • Abstraction
    • Encapsulation
    • Inheritance
    • Polymorphism


What is class in java?

A class is a user defined blueprint or prototype from which objects are created. It represents the set of properties or methods that are common to all objects of one type. In general, class declarations can include these components

  • Modifiers: A class can be public or has default access.
  • Class name: The name should begin with a initial letter
  • Superclass: The name of the class’s parent, if any, preceded by the keyword extends. A class can only extend one parent.
  • Interfaces: A comma-separated list of interfaces implemented by the class, if any, preceded by the keyword implements. A class can implement more than one interface.
  • Body: The class body surrounded by { } braces.


What is an object in Java?

An entity that has state and behavior is known as an object e.g., chair, bike, mobile, pen, table, bike, etc. It can be physical or logical. The example of an intangible object is the banking system.

An object has three characteristics
  • State: represents the data of an object.
  • Behavior: represents the behavior of an object such as deposit, withdraw, etc.
  • Identity: An object identity is typically implemented via a unique ID. The value of the ID is not visible to the external user. However, it is used internally by the JVM to identify each object uniquely.
Object Definitions
  • An object is a real-world entity.
  • The object is an entity which has state and behavior.
  • An object is a runtime entity.
  • The object is an instance of a class.


Methods in Java

A method in Java or Java Method is a collection of statements that perform some specific task and return the result to the caller. A Java method is a collection of statements that are grouped together to perform an operation.

Methods in Java allow us to reuse the code without retyping the code. In Java, every method must be part of some class that is different from languages like C, C++, and Python.

Types of Methods in Java
  • Predefined Method: In Java, predefined methods are the method that is already defined in the Java class libraries is known as predefined methods. It is also known as the standard library method or built-in method.
  • User-defined Method: The method written by the user or programmer is known as a user-defined method. These methods are modified according to the requirement.


Method Declaration

  • Modifier: It defines the access type of the method i.e. from where it can be accessed in your application. In Java, there 4 types of access specifiers(public,protected,private,default) .
  • Method Name: the rules for field names apply to method names as well, but the convention is a little different.
  • The return type: The data type of the value returned by the method or void if does not return a value.
  • Parameter list: Comma-separated list of the input parameters is defined, preceded with their data type, within the enclosed parenthesis. If there are no parameters, you must use empty parentheses.
  • Method body: it is enclosed between braces. The code you need to be executed to perform your intended operations.
  • Exception list: The exceptions you expect by the method can throw, you can specify these exception

Naming a Method

While defining a method, remember that the method name must be a verb and start with a lowercase letter. If the method name has more than two words, the first name must be a verb followed by adjective or noun. In the multi-word method name, the first letter of each word must be in uppercase except the first word.


Pillars of OOPS



Popular Tags


Scroll to Top