JAVA – Data Hiding and Encapsulation

Data hiding or encapsulation is a technique where data is hidden within a class. Only methods that call this data have access to it. Data encapsulation hides private methods and other data members inside the class, which can be accessed by the public methods.

This method hides the code which is written to perform the operation for which the class is written. This will help the programmers to easily modify the code of the class without worrying about the existing code details.

Encapsulation of data also restricts the programmer access to the entire program code. Often, some classes within a program contain a number of fields which are dependant on each other and should not be changed. Also, they should not be accessed by everyone. A programmer can change any of these fields without changing others, and this can result as a class in inconsistent state.

They can instead use a method to change these fields, which will make sure that everything is done to keep class in working condition and consistent. Similarly, we can define internal methods of a class and can prevent calling them from outside the class by other user. The programs written with data encapsulation in mind, describes only those methods that define allowed operations by objects of that particular class. This class has been carefully tested and will work as desired. However, if a program is written without considering all this, it is possible that you need to put a lot of testing effort.

Sometime fields and methods make the programming code look cluttered and unclear. If the number of fields is less, not only the code looks clear but also it becomes easier understand the code. Also, it leads to minimum documentation, saving both programming time and effort.

Java

Continue reading JAVA – Data Hiding and Encapsulation

Object Oriented Approach

Java is one of the commonly used object-oriented programming languages. It is developed specifically for creating distributed programs on shared networks and on the World Wide Web.

Programming is often seen as the integration of logical statements, not as the process of defining data. The concept used in object-oriented programming is about focusing on the objects to be manipulated rather than the logic to be applied in the process. The objects involved in the object-oriented programming range from human beings (defined by name, address, and so forth) to locations (whose properties can be specifically defined and managed) and even tools that you use on your computer (such as navigation bars and action buttons). In a program using the object-oriented approach, the procedures are logically arranged to take input data, apply the definite process and then produce a data output.

Continue reading Object Oriented Approach