
EncapsulationĮncapsulation is closely tied to Abstraction. In Java, abstraction is implemented through Abstract classes and Interfaces.
Best website to learn java driver#
For example, in the real world, a driver does not need to know how the engine of his car works all he needs to know is that if he presses the pedal, the car accelerates. It is useful for reducing the complexity of a system.

AbstractionĪbstraction is the idea of moving the focus from the details of how specific things work to the operations available. Polymorphism allows us to define a makeSound() method in the Pet superclass, and define different behavior in the subclasses. However, if we decide to implement a bark() method in the Dog class and a meow() method in the Cat class, the program would always have to check which type of pet it is dealing with in order to make a sound. For example, we all know that dogs bark and cats meow. Polymorphism allows for the definition of some sort of action with potentially many ways to perform that action. In Java code, that would look like this: Polymorphism We would then have the Cat and Dog subclasses inherit from the Pet class, and would define some unique properties for each – for example, a cat can climb trees and a dog can wag its tail. So, if we were to represent them in Java, we would make a Pet superclass, where we define what the various pets have in common – for example, they all have a name, and they all can drink and eat. For example, cats and dogs are both pets. TInheritance allows objects to receive (or inherit) the attributes and behavior of other objects, while still allowing them to define some unique characteristics. In order to be considered object-oriented, a language must implement the four major principles of OOP: However, object-oriented programming is not just about objects. Instead of having to define the variables and functions for each separate dog, you can just create a Dog class, and then create as many instances of the class as you need. Imagine writing a program for a pet shop. The main benefit that OOP provides is reusability. In this example, “Dog” is the name of the class, while “name” and “breed” are the attributes (what is known about the dog), and “drinkWater”, “eatFood”, and “wagTail” are the operations (what a dog can do in Java these are called methods). For example, in Java, a very simple class for a dog would look like this: A class usually consists of a name, a set of attributes, and a set of operations. Think of a class as a blueprint of a type of object.

However, if each object had to be created individually, this approach would not bring much value, which is why in object-oriented languages, objects are organized into classes. An object defines the types of data that is known about it, and the various actions that it can perform. For example, in a program that simulates a zoo, objects would represent the different types of animals. An object in a program is meant to be a representation of a real-world object.


As the name suggests, OOP is based on the idea of using objects. The concept of object-oriented programming emerged in the early 1970s as an alternative to procedural programming. This was a solid approach, but in larger programs it tended to create code that was difficult to understand and maintain. The procedural philosophy encouraged the separation of the data from the functionality of the program. These instructions would be executed one by one in order, while occasionally calling sub-routines along the way.
Best website to learn java software#
Before object-oriented programming (OOP) gained momentum, the dominating software design methodology was procedural programming, which is, essentially, a series of instructions for the computer. Understanding Object-Oriented Programmingīecause Java is object-oriented, no discussion about the language can be complete without explaining what this concept means.
