Skip to main content

What is the difference between Abstraction and Encapsulation?

I'm sure You came here to see the answer after vising plenty of websites and which is not enough to understand about that concept. The reason why you cant get the perfect or believable answer abut this concept is you're not reading the whole content slowly and carefully. But im sure if you read this fully and carefully, you can earn the knowledge about the difference between Abstraction and Encapsulation. and here we are gonna teach you the real time scenario of Abstraction and Encapsulation. ok!  Lets go to the Topic.

What is Abstraction:

"Abstraction is a process of hiding the implementation details and showing only functionality to the user."


You could see this answer in many websites. Let me explain about what is implementation and functionality. 

For Example,

" Dhoni is a cool captain" Cool is his nature it is his Function. He is always cool even the Team is in underpressure. So cool is his Natural Function.
And, We dont know how he is so cool in underpressure, we cant understand his thoughts how coolest person on the field he is that is his Implementation. That kind of Implementation you cant understand and you dont know.

In java, we know many inbuild function(Here im saying about Class,Interfaces) is available like, JAVA I/O, Thread, etc
for Example, we know the function of FileInputStream class and we know how to use and we know where to use and we know the functionlity of FileInputStream class
But we really dont know how that FileInputStream class implemented exactly. we know only its function and FileInputStream class holding the implementation which we cant see!
ok! now let me explain more!

You're doing a project for School management System. you need to maintain a database for students and staffs. In that Database you have to maintain all of the details about the students and staffs. now what you have to do is, you need to create a seperate class for Students and seperate class for Staffs. then you have to create another class which is a main class and you need to call from main class to Student class and Main class to Staff class.




Above Picture tells everything,
Two Abstract class and One main class. Here we need to create instance for main class only (Abstract class doesn't have instance variable). If we see in Main class, we cant see the implementation of Student abstract class's method and Staff abstract class's method, but when we create main class instance, it will automatically call abstract class since we declare its function alone(Not full implementation) inside the main method.


What is Encapsulation:

"Encapsulation in java is a process of wrapping code and data together into a single unit, for example capsule i.e. mixed of several medicines."

This you can see in many websites,

wrapping the data it means protecting the data from others. for achieving that we are using Access Specifiers like public, private, protected.


In order to Achieve Encapsulation, we need to use Getter and setter method. and we have to call by using that getter and setter method not by directly calling it by using that variable name.


Main Difference:

You do abstraction when deciding what to implement. (Student Abstract class and Staff abstract Class)
You do encapsulation when hiding something that you have implemented. (Getter and Setter method)

Popular posts from this blog

CONVERTING TORRENT FILE TO ZIP FILE

HOW TO CONVERT TORRENT FILE TO ZIP FILE 1>>click the link below  http://www.zbigz.com   2>>upload your .torrent file  3>>wait until conversion, after conversion your  file can be downloadable in .zip format.

Responsive PanelGrid in JSF Primeface

Here, we are going to learn about responsive PanelGrid in JSF Primeface component. As we know primefaces providing lots of good stuffs for JSF. In Primeface, there is a component name Panel Grid which we are going to use for our convenience. In most of the cases, PanelGrid used for making our content in a proper way. If users opens our website which we have made in jsf using panelGrid component that not in responsive manner, that could be really ugly as for as user concern, So here we are going to break it just by using Layout attribute in the panel Grid component. for exaple, < h3 >Responsive</ h3 > < p:panelGrid columns = "3" layout = "grid" >                 < h:outputText value = "Content" />      < h:outputText value = "Content" />      < h:outputText value = "Content" />      < h:outputText value = "Content" />      < h:outputText value = "Content" />

How to clear Filter value in Primefaces Datatable?

As we Know, primefaces provides plenty of components for JSF. In this discussion, we are going to uncover filter attribute mystery in Datatable. Above the pic represents the filter option which is available in primeface . we can easily inherit filter option to datatable. PROBLEM WE FACE: while doing filter in datatable primeface, if we want to go further action. for example, you have 1000 of records, you're filtering option to filter those records. while filtering, you have seen your records and you need to go another action, at the time filter wont be clear. it will be remains same. Inorder to overcome that issue, we need to use below scripts, RequestContext.getCurrentInstance().execute("PF('any_name').clearFilters()"); Add widgetwar attribute in your datatable component <p:datatable id="d_id"   widgetVar ="any_name">