This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Encapsulation & Abstraction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Encapsulation & Abstraction" Watch "Encapsulation & Abstraction" New topic
Author

Encapsulation & Abstraction

Embla Tingeling
Ranch Hand

Joined: Oct 22, 2009
Posts: 237
pankaj vijay wrote:
i am very confused between Encapsulation & Abstraction & Data Hiding.... they all seems like same...
as per my knowledge encapsulation means containing many thing like fields members in an object is encapsulation
Hiding inner working form user is abstraction. while not showing field to the user is Data Hiding...
but am i right???


When you encapsulate something you get an inside and an outside. The outside is data abstraction and the inside is information hiding. Encapsulation concerns how strong this division is, that is to what extent you can poke inside from the outside.

The main encapsulation unit in Java is the class. In principle everything that's exposed to the outside, namely all non-private members, constitute the data abstraction. Hidden inside is the implementation.

An interface is a pure data abstraction.

In object orientation data abstraction manifests itself as user defined types (a type is what you declare variables to be of). Information hiding is the ability to hide information as private members of a class (an enum in Java is a specialized class). So data abstraction is when you define types using the class, interface and enum facilities of Java.

Encapsulation is the ability to separate the what from the how. That is the type (the abstract outside) from how it works inside (a concrete hidden implementation). Encapsulation also is related to questions of mutability/immutability, that is to what extent and how well the inside is isolated from the outside.
pankaj vijay
Ranch Hand

Joined: Apr 01, 2008
Posts: 75
Hii

i am very confused between Encapsulation & Abstraction & Data Hiding.... they all seems like same...
as per my knowledge encapsulation means containing many thing like fields members in an object is encapsulation
Hiding inner working form user is abstraction. while not showing field to the user is Data Hiding...
but am i right???


Pankaj Vijay (SCJP, SCBCD)
Learn Core Java,Learn Servlet Jsp, SCJP Questions,Struts Tutorial
Embla Tingeling
Ranch Hand

Joined: Oct 22, 2009
Posts: 237
It has finally happened. I posted so fast that my reply arrived before the OP asked the question.
Ryan Beckett
Ranch Hand

Joined: Feb 22, 2009
Posts: 192
Hi pankaj vijay,

They both involve information hiding but in different ways. I was taught that encapsulation is information hiding in class files, so other programmers can't learn the inter-workings of the class. This way they can't break your code or call a method that's meant to be private. I don't want other programmers calling setXXX() from their code. By making your instance variables and methods private, your code is safe. Abstraction in programming languages is like this. High Level programming (Java, C) is an abstraction of low level programming (x386, MIPS) in that a lot of the code required in low level programming has already been written and hidden to the programmer. Instead of writing:



in low level, it's simply



in high level. The details are hidden to make the coding easier. The abstract modifier in Java indicates that a class is a general or "base" class that can be implemented in various ways.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3817

uj nossnahoj wrote:It has finally happened. I posted so fast that my reply arrived before the OP asked the question.

How can that happen
Embla Tingeling
Ranch Hand

Joined: Oct 22, 2009
Posts: 237
Vijitha Kumara wrote:
How can that happen


Well, we must've travelled through a time warp. Or maybe it has something to do with daylight saving time that confused the forum software?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3817

Hmmm, Admins will have to take a look at this (not sure whether this has happened before).
Embla Tingeling
Ranch Hand

Joined: Oct 22, 2009
Posts: 237
double posted
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

I've reported the issue to our team of sheriffs. Let's see if they can find out what happened here.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3003
    
    9
Well, the first two posts definitely occurred at the right time to be affected by the DST change, if the server is in the Mountain Time Zone. Probably pankaj vijay's post was at 0737 GMT, and uj's was at 0816 GMT. In Mountain Time these are 1:37 MDT (before the switch), and 1:16 AM MST (after the switch). If the forum software sorts using Mountain Time, and does not include MDT/MST info in the string being sorted, that would account for what we see here.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

uj nossnahoj wrote:It has finally happened. I posted so fast that my reply arrived before the OP asked the question.

The times are still unordered (we think that's due to daylight savings time changing), but at least the posts are in the right order.
 
 
subject: Encapsulation & Abstraction
 
Similar Threads
OOP Concepts
Abstraction vs Encapsulation
difference between abstraction and encapsulation
An example of abstraction in java
Doubts in Basic Concepts of OOPS