
Encapsulation is one of the four major concepts behind object-oriented programming (OOP).
By definition, encapsulation describes the idea of bundling data and methods that work on that data within one unit, like a class in Java. This concept is also often used to hide the internal representation, or state of an object from the outside. This is called information hiding.

Why do we need Encapsulation in Java?
The major advantage of encapsulation in Java is data hiding. Using encapsulation we can allow the programmer to decide on the access to data and methods operating on that data. For example, if we want a particular piece of data to be inaccessible to anyone outside the class, then we make that data private.

Encapsulation finds a ton of usage in everyday programming. Some of the very frequent uses are as follows:
- Encapsulation makes programming flexible. This essentially means that you can edit and update code according to new specifications.
- It helps you in achieving loose coupling.
- Encapsulation makes the application simple and easy to debug.
- You can change and make edits to your codebase without disrupting the normal functioning of your program.
- Allows the programmer to control the data accessibility of a class.

Types of Encapsulation

Disadvantages of Encapsulation
- Code Size: The length of the code increases drastically in the case of encapsulation as we need to provide all the methods with the specifiers.
- More Instructions: As the size of the code increases, therefore, you need to provide additional instructions for every method.