Encapsulation and Tunneling

📦 Encapsulation Encapsulation is the process of wrapping data with the necessary protocol information at each layer of the OSI or TCP/IP model. Each layer adds a header (and sometimes a footer) to the data from the upper layer. Enables modular communication: the lower layers do not need to understand the data they are transporting. 🔄 Example (Sending a Web Page over TCP/IP): Application Layer: HTTP Data Transport Layer: Adds TCP Header → TCP Segment Network Layer: Adds IP Header → IP Packet Data Link Layer: Adds MAC Header/Footer → Frame Physical Layer: Converts to Bits for transmission 🕳 Tunneling Tunneling is a method of encapsulating packets within another protocol to route over a network where the original protocol might not be supported. ...

May 12, 2025 · 2 min · Rohan

Encapsulation

🔐 Encapsulation Encapsulation is one of the four core principles of Object-Oriented Programming. It involves wrapping data and code that operates on the data into a single unit: the class. 🧩 Key Concepts Declaring variables as private to prevent direct access from outside. Providing public methods (getters/setters) to read or modify private variables. Helps enforce data protection, validation, and clean APIs. 📌 Why Use Encapsulation? Keeps internal implementation hidden Prevents external interference or misuse Allows safe and controlled access Promotes modularity and maintainability 🧪 Java Example class Student { private int age; // Setter with validation public void setAge(int a) { if (a > 0) age = a; } // Getter public int getAge() { return age; } } 🔗 Related Notes History and Evolution OOPs Principles Features of Java Inheritance Polymorphism Abstraction

May 8, 2025 · 1 min · Rohan