OOPs Concepts in Java | Learn from Basics with Examples
Java OOPs Concepts Tutorial ACTE

OOPs Concepts in Java | Learn from Basics with Examples

Last updated on 10th Feb 2022, Blog, Tutorials

About author

Divan Singh (Java Developer )

Divan Singh is a Java Developer and contributes in-depth articles on various Big Data Technologies. He also has experience with Hadoop, Microservices, Commvault, and a few BI tools.

(5.0) | 16129 Ratings 3257
    • Introduction to Java OOPs Concepts
    • History of Java OOPs Concepts
    • What is Object-Oriented Programming?
    • OOP s (Object-Oriented Programming System)
    • List of OOPs Concepts in Java with Examples
    • Basic Components
    • Application of Object-Oriented Programming
    • Object-Oriented Programming (OOP) versus Procedure Oriented Programming (POP)
    • Abstract Class and Methods in OOPs Concepts
    • Methods in Java
    • Advantage of OOPs over Procedure-situated programming language
    • Certification and Cost
    • Pre- Requisites
    • Conclusion

    Subscribe For Free Demo


      Introduction to Java OOPs Concepts:

      1. In this instructional exercise, we will find out with regards to the rudiments of OOPs. Object-Oriented Programming is a worldview that gives numerous ideas, for example, inheritance, data binding, polymorphism, and so on.

      2. Simula is viewed as the main article arranged programming language. The programming worldview where everything is addressed as an item is known as a genuinely object-arranged programming language.

      3. Smalltalk is viewed as the first fundamental point of article situated writing computer programs is to carry out certifiable elements, for instance, object, classes, deliberation, inheritance, polymorphism, etc.t object-arranged programming language.

      The famous article situated Languages are Java:

    • C#
    • PHP
    • Python
    • C++ and etc.,

    • The principle point of article situated writing computer programs is to execute certifiable substances, for instance, object, classes, reflection, inheritance, polymorphism, and so on.

      What Is an Object?

      An article is a product heap of related state and conduct. Programming objects are regularly used to display these present reality protests that you find in daily existence. This example clarifies how state and conduct are addressed inside an article, presents the idea of information embodiment, and clarifies the advantages of planning your product as such.

      What Is a Class?

      A class is a plan or model from which items are made. This part characterizes a class that models the state and conduct of a genuine item. It deliberately centers around the essentials, showing how even a straightforward class can neatly display state and conduct.

      What Is Inheritance?

      Inheritance gives a strong and regular system for getting sorted out and organizing your product. This segment clarifies how classes acquire state and conduct from their super classes and discloses how to get one class from one more utilizing the basic punctuation given by the Java programming language.

      What Is an Interface?

      A connection point is an agreement between a class and the rest of the world. At the point when a class carries out a point of interaction, it vows to give the conduct distributed by that point of interaction. This part characterizes a basic point of interaction and clarifies the vital changes for any class that carries out it.

      What Is a Package?

      A bundle is a namespace for getting sorted out classes and points of interaction in a consistent way. Setting your code into bundles makes huge programming projects more straightforward to make due. This part clarifies why this is valuable, and acquaints you with the Application Programming Interface (API) given by the Java stage.

      History of Java OOPs Concepts:

    • While learning Object-Oriented Programming. I chose to jump into its set of experiences and it ended up being interesting. The expression “Item-Oriented Programming” (OOP) was instituted by Alan Kay around 1966 while he was at graduate school. The language called Simula was the principal programming language with the highlights of Object-situated programming. It was created in 1967 for making recreation programs, in which the main data was called objects.

    • However, OOPs were in the market since the mid-1960s it was during the 1990s that OOPs started to develop due to C++. After that, this strategy of programming has been adjusted by different programming dialects including Python Today its application is in pretty much every field, for example, Real-time frameworks, Artificial knowledge, and master frameworks, Client-server frameworks, Object-situated information bases, and some more.

    • What is Object-Oriented Programming?

      a) Object-Oriented Programming (OOP), is tied in with making “objects”. An item is a gathering of interrelated factors and capacities. These factors are frequently alluded to as properties of the item and capacities are alluded to as the conduct of the articles. These items give a superior and clear construction for the program.

      b) For instance, a vehicle can be an item. On the off chance that we consider the vehicle as an article, its properties would be – its tone, its model, its value, its image, and so on Furthermore its conduct/capacity would be speed increase, dialing back, gear change.

      c) Another model If we consider a canine as an item then, at that point, its properties would be-his tone, his variety, his name, his weight, and so forth Furthermore his conduct/capacity would walk, yap, playing, and so on

      d) Object-Oriented writing computer programs are well known because it carries out this present reality substance like items, stowing away, inheritance, and so forth in programming. It makes perception more straightforward because it is near true situations.

      OOP s (Object-Oriented Programming System):

      Object implies a genuine substance like a pen, seat, table, PC, watch, and so on Object-Oriented Programming is a philosophy or worldview to plan a program utilizing classes and items. It works on programming improvement and upkeep by giving a few ideas:

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

    • Aside from these ideas, there are a few different terms that are utilized in Object-Oriented plans:

      1. Coupling

      2. Cohesion

      3. Association

      4. Aggregation

      5. Composition

      List of OOPs Concepts in Java with Examples:

      Coming up next are general OOPs ideas in Java:

      1) Class: The class is one of the Basic ideas of OOPs which is a gathering of comparative elements. It is just an intelligent part and not the actual substance. Let us comprehend this one of the OOPs Concepts with a model, on the off chance that you had a class called “Costly Cars” it could have objects like Mercedes, BMW, Toyota, and so forth Its properties(data) can be cost or speed of these vehicles. While the strategies might be performed with these vehicles are driving, inverting, slowing down, and so on

      2) Object: An article can be characterized as a case of a class, and there can be different causes of a class in a program. An Object is one of the Java OOPs ideas which contains both the information and the capacity, which works on the information. For instance – seat, bicycle, marker, pen, table, vehicle, and so forth

      3) Inheritance: Inheritance is one of the Basic Concepts of OOPs in which one item obtains the properties and practices of the parent object. It’s making a parent-kid connection between two classes. It offers a strong and normal instrument for getting sorted out and design of any product.

      4) Polymorphism: Polymorphism alludes to one of the OOPs ideas in Java which is the capacity of a variable, article, or capacity to take on numerous structures. For instance, in English, the action word run has alternate importance if you use it with a PC, a foot race, and business. Here, we comprehend the importance of run because of the different words utilized alongside it. The equivalent is additionally applied to Polymorphism.

      5) Abstraction: Deliberation is one of the OOP Concepts in Java which is a demonstration of addressing fundamental highlights without including foundation subtleties. It is a procedure of making another information type that is appropriate for a particular application. Let us comprehend this one of the OOPs Concepts with the model, while driving a vehicle, you don’t need to be worried about its inside working. Here you simply need to worry about parts like the guiding wheel, Gears, gas pedal, and so on

      6) Encapsulation: Exemplification is one of the most mind-blowing Java OOP’s ideas of wrapping the information and code. In this OOPs idea, the factors of a class are concealed all the time from different classes. It must be gotten to utilizing the Methods for their present class. For instance – in school, an understudy can’t exist without a class.

      7) Association: Affiliation is a connection between two items. It is one of the OOP Concepts in Java which characterizes the variety between objects. In this OOP idea, all articles have their different lifecycle, and there could be no proprietor. For instance, numerous understudies can connect with one instructor while one understudy can likewise connect with different educators.

      8) Aggregation: In this method, all items have their different lifecycle. Notwithstanding, there is a proprietorship to such an extent that youngster objects can’t have a place with another parent object. For instance, think about class/objects division and instructor. Here, a solitary instructor can’t have a place with various offices, however, regardless of whether we erase the division, the educator item won’t ever be obliterated.

      9) Composition: The organization is a particular type of Aggregation. It is likewise called a “passing” relationship. Kid objects don’t have their lifecycle so when the parent object erases all kid items will likewise erase naturally. For that, we should accept an illustration of the House and rooms. Any house can have a few rooms. One room can’t turn out to be important for two unique houses. In this way, assuming you erase the house room will likewise be erased.

      Basic Components:

      Access Modifier: Defines access kind of the Method for example from where it very well may be gotten to in your application. In Java, there 4 kinds of entrance specifiers.

      Public: Available in all classes in your application.

      Safeguarded: Available inside the bundle in which it is characterized and, in its subclass, (es) (including subclasses announced external the bundle)

      Private: Open just inside the class in which it is characterized.

      Default (announced/characterized without utilizing any modifier): Open inside the same class and bundle inside which its class is characterized.

      The bring type back: The information sort of the worth returned by the strategy or void it doesn’t return a worth.

      Strategy Name: The guidelines for field names apply to Method names too, however, the show is somewhat unique.

      Boundary list: Comma isolated rundown of the info boundaries is characterized, went before with their information type, inside the encased bracket. Assuming there are no boundaries, you should utilize void enclosures ().

      Exemption list: The special cases you expect by the strategy can toss; you can indicate these exception(s).

      Strategy body: it is encased between supports. The code should be executed to play out your planned activities.

      Message Passing: Objects speak with each other by sending and getting data to one another. A directive for an item is a solicitation for the execution of a strategy and thusly will summon a capacity in the getting object that produces the ideal outcomes. Message passing includes determining the name of the item, the name of the capacity, and the data to be sent.

      Presently with essential to step learning 4 mainstays of OOPS is as per the following. Allow us to begin with finding out with regards to the various qualities of an Object-Oriented Programming language.

      Application of Object-Oriented Programming:

    • Client-Server Systems.
    • Object-Oriented Databases.
    • Object-Oriented Databases.
    • Continuous System Design.
    • Reproduction and Modeling System.
    • Hypertext and Hypermedia.
    • Neural Networking and Parallel Programming.
    • Office Automation Systems

    • Course Curriculum

      Develop Your Skills with Programming in HTML5 with JavaScript and CSS3 Certification Training

      Weekday / Weekend BatchesSee Batch Details

      Object-Oriented Programming (OOP) versus Procedure Oriented Programming (POP):

      The fundamental distinction among OOP and procedural writing computer programs is-

      1. One method for pondering POP is the same way you make lemonade for instance. The strategy of making lemonade includes first taking water as indicated by the need, then, at that point, adding sugar to the water, then, at that point, adding lemon juice to the combination, lastly blending the entire arrangement. What’s more, your lemonade is prepared to serve.

      2. Likewise, POP requires a specific Method of steps. A procedural program comprises capacities. This intends that in the POP methodology the program is isolated into capacities, which are explicit to various errands. These capacities are organized in a particular grouping and the control of the program streams successively.

      3. Though an OOP program comprises of items. The item Oriented methodology partitions the program into objects. Furthermore, these items are the substances that wrap up the properties and the conduct of these present reality objects.

      4. POP is reasonable for little errands as it were. Since as the length of the program builds, the intricacy of the code additionally increments. Also, it winds up turning into a trap of capacities. Additionally, it turns out to be difficult to troubleshoot. OOP takes care of this issue with the assistance of a clear and less perplexing construction. It permits code re-convenience as a inheritance.

      5. Another significant thing is that in system arranged programming every one of the capacities approaches every one of the information, which suggests an absence of safety. Assume you need to get the qualifications or some other basic data from the world. Then, at that point, the procedural methodology neglects to give you that security.

      6. This OOP assists you with one of its astonishing usefulness known as Encapsulation, which permits us to conceal information. Try not to stress I’ll cover this exhaustively in the last option part of this article alongside different ideas of Object-Oriented Programming. For the present, simply comprehend that OOP empowers security and POP doesn’t.

      7. Programming dialects like C, Pascal, and BASIC utilize the procedural methodology while Java, Python, JavaScript, PHP, Scala, and C++ are the principle dialects that give the Object-arranged methodology.

      Abstract Class and Methods in OOPs Concepts:

      Abstract Method:

      1) A Method that is pronounced yet not characterized. Just Method signature nobody.

      2) Declared utilizing the theoretical catchphrase

      3) Example: theoretical public void play Instrument ();

      5) Used to place some sort of impulse on the class who acquires the class has theoretical Methods. The class that acquires should give the execution of the multitude of unique strategies for parent class else pronounce the subclass as Abstract.

      6) These can’t be Abstract


      Static Methods

      Private Methods

      Methods that are announced “last”

      Abstract Class

      A theoretical class traces the strategies however not carry out every one of the Methods.

      Note 1: There can be a few situations where it is challenging to carry out every one of the Methods in the base class. In such situations, one can characterize the base class as a theoretical class which implies that this base class is an exceptional sort of class that isn’t finished all alone. A class got from the theoretical base class should execute those Methods that are not implemented (means they are Abstract) in the theoretical class.

      Note 2: Abstract class can’t be launched which implies you can’t make the object of a unique class. To utilize this class, you want to take another class that expands this theoretical class gives the execution of conceptual Methods, then, at that point, you can utilize the object of that youngster class to call non-Abstract parent class strategies as well as carried out methods (those that were unique in parent yet carried out in kid class).

      Note 3: If a youngster doesn’t execute every one of the theoretical strategies for parent class (the Abstract class), then, at that point, the kid class should be pronounced unique.

      Methods in Java:

      A Methods in java is a square of code or assortment of articulations gathered to get done with a specific task or activity. A strategy is utilized to accomplish the reusability of code. A strategy is composed once and can be used ordinarily. It likewise gives the simple alteration and lucidness of code. A strategy is executed just when we call or conjure it. We have two classes of Methods in java, i.e., pre-characterized and client characterized. Predefined strategies are the Methods that are now characterized in the Java class libraries. At the point when the specific strategy is composed by the client or software engineer, it is known as a client characterized Method. Client characterized strategies can be adjusted by the prerequisite.

    • Static Method in Java
    • Abstract Method in Java
    • Finish Method in Java
    • Equals Method in Java

    • Static Method in Java:A Method that has the static watchword in the statement is known as the static strategy. All in all, a strategy that has a place with a class rather than an occasion of a class is known as a static Method. We can likewise make a static strategy by utilizing the catchphrase static before the Method name. The principle advantage of a static strategy is that we can conjure the static Method without making an article. It can get to static information individuals and change their qualities. It is utilized to make a case Method. It is summoned by utilizing the class name. The fundamental() Method is a typical illustration of the static strategy.

      Course Curriculum

      Get JOB Oriented Programming in HTML5 with JavaScript and CSS3 Training for Beginners By MNC Experts

      • Instructor-led Sessions
      • Real-life Case Studies
      • Assignments
      Explore Curriculum

      Abstract Method in Java:A Method that is announced with a watchword conceptual is called a theoretical strategy. The theoretical strategy doesn’t have an execution or body, or square of code. The theoretical strategy should constantly be announced in a theoretical class, or we can say that assuming a class has a theoretical Method, it should be pronounced unique. Assuming a class has a theoretical strategy, it should be announced unique, yet the other way around isn’t correct, and that implies that a theoretical class doesn’t have to have a theoretical Method necessary. Additionally, If an ordinary class broadens a theoretical class, then, at that point, the class should need to carry out all the theoretical parent class’ theoretical strategies, or it must be pronounced unique.

      Final Method in Java:A Method that is proclaimed last is known as the last strategy. We can’t supersede the last strategy. This implies the kid class can in any case call the last strategy for parent class with practically no issue, yet it can’t abrogate it. This is because the principle motivation behind making a Method last is to stop the alteration of the strategy by the sub-class.

      Equal Method in Java:In Java, the String Equals () strategy thinks about the two given strings because of the information/content of the string. Assuming every one of the substances of both the strings is something very similar, it brings valid back. If all characters are not coordinated, then, at that point, it gets back misleading.

      Advantage of OOPs over Procedure-situated programming language:

    • OOPs makes improvement and support more straightforward, though, in a methodology situated programming language, it isn’t difficult to oversee assuming code develops as task size increments.
    • OOPs gives information stowing away, while, in a methodology arranged programming language, worldwide information can be gotten to from any place.
    • OOPs gives the capacity to recreate certifiable occasion considerably more actually. We can give the arrangement of genuine word issues assuming that we are utilizing the Object-Oriented Programming language.
    • OOPs Concepts in Java offer straightforward and reasonable particular construction for programs.
    • Objects made for Object-Oriented Programs can be reused in different projects. In this way, it saves critical advancement costs.
    • Huge projects are challenging to compose, yet on the off chance that the turn of events and planning group follow OOPS ideas, they can more readily plan with the least blemishes.
    • It improves program seclusion because each item exists autonomously.

    • Certification and Cost:

      Assuming that you’re searching for a free Java course, redesign offers a great free Java course as a piece of its upstart-Priceless Learning drive. upstart is up Grad’s free learning environment planned only to assist hopefuls with creating significant and moving industry abilities to remain in front of the cutthroat bend.

      Pre- Requisites:

      You should know the fundamentals of how to utilize a PC, and ought to have the option to begin an order line shell. On the off chance that you are new to programming, Introduction to Programming is firmly suggested. If you definitely know C++ or some other Object-Oriented language, Java ought to be not difficult to get.

      Java Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download


      To compose great quality projects, a software engineer should have a firm order of OOP ideas. Object-arranged programming spins around the idea of an article, which embodies information and conducts following up on the information together. An article offers its types of assistance through a distinct point of interaction.

    Are you looking training with Right Jobs?

    Contact Us

    Popular Courses

    Get Training Quote for Free