File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Use of encapsulation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Use of encapsulation" Watch "Use of encapsulation" New topic

Use of encapsulation

Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 418
Encapsulation means wrapping up of member data and member functions together and this is a feature of OOP.
But,what it the benefit we are getting by using encapsulation or in other words what we will be loosing if not using encapsulation.
thanks in advance.
sammaiah kyatham
Ranch Hand

Joined: Aug 03, 2003
Posts: 104
There are several advantages of encapsulation.
The primary advantage is data access and managing data for a specific entity/Object.
Encapsulation allows you to bind the data within the object and provides set of operations to manipulate the data.

I'm not sure whether you are happy with my answer but you'll understand practically if you write one C program and java program for same requirement like managing employee data.

Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
The main advantage of encapsulation is that it keeps your code maintainable. By keeping things that are closely coupled also close together in the source code, it becomes easier to assess the impact of changes to the code.

For example, imagine that a value that until now has been stored in a field should now be calculated one the fly from the value of another field. That's easy to do if the field is only directly accessed from inside the class and all other clients go through methods. Without encapsulation, it can even become impossible - especially when not all clients are under your direct control.

Does that help?

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: Use of encapsulation
It's not a secret anymore!