✔ JAVA CHAPTERS:-
1. Introduction to Java
2. Features of Java
3. Java Virtual Machine
4. D/F B/W JVM, JRE, JDK
5. Java Data Types
6. Java Programs
7. Setting Java Path
8. OOPs Concepts
9. Object & Class In Java
10. OOPs Continued
11. Encapsulation & Polymorphism
12. Method Overloading
13. Method Overriding
14. Dynamic Method Dispatch
15. Association In Java
16. Inheritance in Java
17. Aggregation in java
18. Command Line Argument
19. Execute Command Line
20. Read Input From Command Line
21. Abstract Class In Java
22. Interface in Java
23. Cutom Marker Interface
24. Constructor In Java
25. Package in Java
26. Acess Modifier In Java
27. Static Import In Java
28. Package Class In Java
29. This Keyword
30. Instance Intializer Block
31. Super Keyword
32. Static Keyword
33. Final Keyword
1. Introduction to Java
2. Features of Java
3. Java Virtual Machine
4. D/F B/W JVM, JRE, JDK
5. Java Data Types
6. Java Programs
7. Setting Java Path
8. OOPs Concepts
9. Object & Class In Java
10. OOPs Continued
11. Encapsulation & Polymorphism
12. Method Overloading
13. Method Overriding
14. Dynamic Method Dispatch
15. Association In Java
16. Inheritance in Java
17. Aggregation in java
18. Command Line Argument
19. Execute Command Line
20. Read Input From Command Line
21. Abstract Class In Java
22. Interface in Java
23. Cutom Marker Interface
24. Constructor In Java
25. Package in Java
26. Acess Modifier In Java
27. Static Import In Java
28. Package Class In Java
29. This Keyword
30. Instance Intializer Block
31. Super Keyword
32. Static Keyword
33. Final Keyword
Oops Concepts in Java: Previous Next: Method Overloading
Encapsulation in java
Dictionary meaning of Encapsulation:
The condition of being enclosed.
Capsule:
Capsule refers to a small container which contains a dose of medicine.
Definition of Encapsulation:
Encapsulation is a process of wrapping code and data into a single unit.
Encapsulation in real world:
Let us take an example of a HR in a company. We communicate through HR not directly with the departments. HR is acting as a public interface here.
Encapsulation in programming:
Encapsulation is the way of declaring the data members as private and providing access to the data members through public methods (getter and setter methods). As private field can’t be access outside the class that means data is hiding within the class. That’s why encapsulation is also known as data hiding.
Important points:
1. Main Concept behind encapsulation is ‘control over the data’. It is achieved using class and access modifier private, protected, public. Class is act as a container which contains code and data.
2. Factory pattern and Singleton pattern in Java are based on the concept encapsulation.
2. Factory pattern and Singleton pattern in Java are based on the concept encapsulation.
Example:
Car.java
CarTest.java
Output:
Advantages/Benefits of Encapsulation:
- 1. A read-only (immutable) or write-only class can be made.
- 2. Control over the data.
- 3. It helps in achieving high cohesion and low coupling in the code.
Polymorphism In Java
Polymorphism in real world:
Polymorphism means more than one forms. Water can be of in any form solid, liquid or gas.
Polymorphism in programming:
In java polymorphism is a way in which something behaves differently based on its call. Let us take the example of + operator and see the below example.
PolymorphismExample.java
Output:
In the above example + operator behaves differently based on type of argument. When arguments are of integer type it acts as additional operator and when arguments are of String type it acts as concatenation operator.
Polymorphic object:
In java an object which can pass two or more IS-A test. All objects in java are polymorphic in nature because they passed IS-A test at least for its own type and Object class type.
Types of polymorphism:
- Static/compile time polymorphism (by method overloading).
- Dynamic/run time polymorphism (by method overriding).