Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Encapsulation in java

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

Here is a defination of Encapsulation from a site


Encapsulation refers to the bundling of data with the methods that operate on that data, and also some say that ENcapsulation is data hiding .

From this i understand that Encapsulation is nothing but a java bean with private properties and public methods .

Please guide me here .
 
K. Tsang
Bartender
Posts: 3397
13
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
encapsulation? Your definition is correct. It is data hiding because the class uses public getters/setting to retrieve/assign "private" variables. And the class is practically a JavaBean.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much
 
Ulrika Tingle
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Kiran V wrote:
From this i understand that Encapsulation is nothing but a java bean with private properties and public methods .


In OO, encapsulation is a little more than that. When you encapsulate something you get an inside and an outside. The outside is called a data abstraction, or the type. The inside is called information hiding, or the implementation. So in principle encapsulation is the separation of a visible type from a hidden implementation, or the division of something into "what" you can see and use, from "how" it's done. Most importantly the type and the implementation become independent of each other and can be changed separately.

The main units of encapsulation in Java is the class, the enum and the interface (each with somewhat different encapsulation properties). The type is the signature and behaviour of all non-private methods and fields of these language elements. The implementation is the code inside including private methods and fields.

Encapsulation is very important in Java. It's at the very heart of OO programming. Defining appropriate types and cleverly hiding implementation is the process that drives the design and development of Java programs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic