In a programming language, encapsulation is used to refer to one of two related but distinct notions, and sometimes to the combination.
Encapsulation is the mechanism that binds together code and the data it manipulates and keeps both safes from outside interference and misuse.
One way to think about encapsulation is a protective wrapper that prevents the code and the data from being arbitrarily accessed by other code defined outside the wrapper. Access to the code and the data inside the wrapper is tightly controlled through a well-defined interface.
In Java, the basis of encapsulation is the class.