Java | Encapsulation :

              ~~ CORE-JAVA ~~

 1. INTORDUCTION

     1.1 Java Intorduction
     1.2 Java history
     1.3 Java features
     1.4 Diff b/w Java & C++
     1.5 Java Variables
     1.6 Java Data Types
     1.7 Typecasting
     1.8 Arrays

 2. OOPS

     2.1 Introduction
     2.2 Class
     2.3 Object
     2.4 Static Keywords
     2.5 Constructors
     2.6 This KeyWord

 3. INHERITANCE

     3.1 Inheritance (IS-A) 
     3.2 Aggregation (HAS-A)

 4. POLYMORPHISM

     4.1 Polymorphism & Its Type
     4.2 Method Overloading
     4.3 Method Overriding
     4.4 Super Keyword
     4.5 Final Keyword
     4.6 Dynamic Binding

 5. ABSTRACTION

     5.1 Abstract Classes & Methods
     5.2 Interfaces
     5.3 Abstract vs Interface

 6. ENCAPSULATION

     6.1 Encapsulation

 7. STRING MANIPULATIONS

     7.1 String
     7.2 String Buffer
     7.3 String Tokenizer

 8. PACKAGES

     8.1 Predefined packages
     8.2 Userdefined Packages
     8.3 Access Specifiers

 9. EXCEPTION HANDLING

     9.1 Introduction
     9.2 Pre Defined Exceptions
     9.3 Try-Catch-Finally
     9.4 Throws, throw
     9.5 User Defined Exception

 10. MULTITHREADING

     10.1 Introduction
     10.2 Thread Creations
     10.3 Thread Life Cycle
     10.4 Life Cycle Methods
     10.5 Synchronization
     10.6 Wait() notify() notify all()

 11. WRAPPERCLASSES

     11.1 Introduction
     11.2 Wrapper Classes

 12. COLLECTION FRAME WORK

     12.1 Introduction
     12.2 List interface
     12.3 Set interface                     12.4 Map interface                           

 13. INNER CLASSES

     13.1 Introduction
     13.2 Member inner class
     13.3 Static inner class
     13.4 Local inner class
     13.5 Anonymous inner class

 14. CoreJava Interview Questions

Introduction :

  • Encapsulation in Java means, Binding the Variable and Methods together. In other word we can say, Encapsulating data and corresponding methods into a single unit is nothing but “Encapsulation”.
  • If any Java class where Data Hiding and Abstraction both are there, we can say it’s encapsulated class.
    • Encapsulation = DataHiding + Abstraction
  • In simple word  we can say, actual meaning of Encapsulation is to make sure that “sensitive” data should be hidden from users. To achieve this we can use :
    • Declare Class variable as private.
    • Providing getter/setter method to access and update these private variable.

Example :

Advantage of Encapsulation :

  1. We can achieve Security.
  2. Enhancement will become very easy.
  3. It will improve modularity of the application.
  4. We can achieve Re-usability also.
  5. It makes our application very flexible, because we can make our data as read-only or write-only as required.
  6. Testing also becomes easy for such type of Class, so it is better for Unit Testing also.

 

Data Abstraction vs Encapsulation :

Help Others, Please Share