Java is an object-oriented programming language. This means that a program is a collection of objects. Note that in the real world, everything is defined as an object and an object can interact with other objects. Java programming follows this philosophy. This means that writing a Java program means you need to create your objects and also mention how your objects interact with other objects which, thus, solves the problem. How an object can be created and the mechanism of object–object interaction, etc., are realized by means of one of the most important object-oriented programming paradigms called encapsulation. This chapter includes discussions related to this programming feature. Indeed, the concept of encapsulation is very important for any programmer to build their skill in Java programming.
Introduction
Object and its concept Objects in this real world are physical entities, which can be seen and touched. For example, trees, tables, computers, fans, people, birds, and so on. Each object consists of several parts. For example, a tree consists of root, trunk, leaves, buds, flowers, fruits, seeds, and so on. Note that a part of the tree can again be another object, for example, a fruit. An object can be defined by its parts. Such a definition would make the object unique and distinguishable from other objects. In addition to the physical elements, objects are also characterized by behavioral parts. For example, a person is an object and has some behavior, such as climbing (a tree), plucking (a flower), cooking (food), and so on. Objects can be used to model our real world (which is also an object!) and then different activities in the world can be carried out.
Object-oriented approach This is the philosophy of how we can build a system using the object-oriented concept. A system can be built on a bottom-up approach. Create the smallest objects. Use several small objects to build larger objects; larger objects are then assembled to build much larger objects, and so on, and then finally the target system is built. For example, if you want to make a computer, then build transistors, use transistors to build logic gates, use logic gates to build circuits, use circuits to build different functional units, use different functional units to build memory, CPU, Keyboard, display unit, and finally, all this makes up your computer.