Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Encapsulate

 
Mike Shn
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really not sure what encapsulate means. As I understand that when data is encapsulate that means that data is hidden(like private) .. Right?
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. It means to keep hidden things you don't want the outside world to know about, and just provide a public API (application programming interface) for the outside world to use.
That way, since you've kept your internal implementation private, you are free to change it later and no one has to know about that change. As long as the API stays the same, users of your class will continue to use your object just as they always have.
 
Junilu Lacar
Bartender
Posts: 7557
52
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an article from JavaWorld that differentiates between encapsulation and information hiding: http://www.javaworld.com/javaworld/jw-05-2001/jw-0518-encapsulation-p2.html
Junilu
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
The article recommended by Junilu is a great article on this topic. I highly recommend reading it.
Good Luck,
-Dirk Schreckmann
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic