Define a class with all the data members declared as private so that they are not publically accessible to any other class and all the methods that works upon or uses these data members as public. In this way encapsulation is achieved in Java.