What is Abstraction in Java?
Abstraction in Java programming language is a feature used in OOPs to hide the codes from the user. With the help of the abstraction feature, only the essential information is shown to the users. For example, in a TV remote, only the keys are shown to the users but not the codes on which it is operating as they are not at all useful to the end-user.
Abstraction is among the four basic concepts of the OOP language. It is very helpful in reducing the complexity of the program. In short, it is said that abstraction is used to "show" essential details and "hide" irrelevant and unnecessary information.
What is Encapsulation in Java?
Encapsulation is another very important feature of the OOP programming language. It is used to reduce the complexity of the software program and helps in creating it more user friendly. Encapsulation creates a user-friendly structure and wraps the code and data into a single entity.
In encapsulation, data members are bound with variables. It is used and known for data hiding. As we have seen in brief about data abstraction and encapsulation, we will now see the difference between them in the next section.
Difference between Abstraction and Encapsulation in Java
Both abstraction and encapsulation are special features of OOP and are useful in various ways. There exist a few differences between the two features which are explained in the table provided below:
Abstraction vs Encapsulation
|This feature is used to hide irrelevant and unnecessary codes from users.||This feature is useful to hide codes into a single unit.|
|Design level issue rectification.||Implementation level issue rectification.|
|Improves the external features.||Improves internal features.|
|Abstract class and interfaces can be used to implement this feature.||Access modifiers are used to implement this feature.|
|Abstraction is done with the help of encapsulated objects.||No abstraction is required for encapsulation.|
|Presentation improves.||Maintainability of the function increases|
|Unit testing is not affected.||Unit testing becomes easier.|