Abstraction vs Encapsulation in Java
Here are some of the main differences between Abstraction vs Encapsulation in Java and OOPS(Object Oriented programming) concept. Abstraction and Encapsulation along with inheritance and polymorphism forms the basis of Object-oriented programming in Java.
1) The first difference between Abstraction and Encapsulation is that, Abstraction is implemented in Java using the interface and abstract class while Encapsulation is implemented using private, package-private and protected access modifier.
2) Encapsulation is also called data hiding.
3) Design principles "programming for interface than implementation" is based on abstraction and "encapsulate whatever changes" is based upon Encapsulation.
Here is a nice diagram that explains the concept of Abstraction in object-oriented programming:-
In this diagram, you can see that the user only knows there is a book window for borrowing and returning books, he doesn't care or doesn't need to know about how the book is found and what happens before and after he requests or return a book. In other words, he is abstracted from all the details involved in getting the book to the window.
Another common example of Abstraction is eating your lunch or dinner. What you care about is eating, you don't need to bother about how the raw materials are produced, cooked, and served, all those things are abstracted from you.
That's all from my side on differences between Abstraction and Encapsulation in Java. Correct understanding of Encapsulation and Abstraction is a must for any Java developer. Head First Object-oriented Analysis and design is a great book to learn more about Abstraction, Encapsulation, and other OOPS concepts.