[vc_row css_animation=”” row_type=”row” use_row_as_full_screen_section=”no” type=”full_width” angled_section=”no” text_align=”left” background_image_as_pattern=”without_pattern”][vc_column][vc_column_text]

Object-oriented programming

[/vc_column_text][vc_separator type=”normal” up=”1″][vc_column_text css=”.vc_custom_1581548005892{background-color: #f6f6f6 !important;}”]

One of the most powerful characteristics in Java is that it is object-oriented programming. The program can be built up as several models (objects) that can integrate with each other.

[/vc_column_text][vc_empty_space height=”30px”][vc_column_text]

Why use object-oriented programming?

By now, you probably already understand why object-oriented programming is so powerful. Each object (instance of a class) stores only information that is relevant to its use, which means that undesirable effects between two objects are minimal. Furthermore, you have seen in this chapter how we can reuse code (inheritance), which allows for more general classes.[/vc_column_text][vc_empty_space height=”20px”][vc_separator type=”normal”][vc_empty_space height=”20px”][vc_column_text]

BENEFITS WITH OBJECT ORIENTED PROGRAMMING

Note that here are just some of the benefits that we think object-oriented programming has, of course, there are several more.

 

  • Reuse code: With the help of Inheritance in Java, we can reuse code from other classes. Many times you want to reuse code from classes you have already programmed. Instead of coding similar classes several times, you can inherit code from another class.

 

  • Flexibility: Because different objects can use the same functions, objects in different classes can use the same methods. For example, we create a method for measuring distance so that we can use that method can for a car, but also a person walking.

 

  • Troubleshooting: When we work with object-oriented programming, it is, in most cases, more comfortable to find where the error has occurred. Objects are standalone, and each part of functionality does its own thing while leaving the other parts alone. For example, we have a problem with our item for a car. It is most likely that the fault is in, or linked to, the class we created for the vehicle.

 

  • More effective problem solving: Because we can divide our programs into objects and classes, we can break down the problem into smaller parts (objects). We can then solve the minor problems, one object at a time. If we have a large complex problem, we can break it down into smaller parts and solve them individually.

[/vc_column_text][vc_empty_space height=”20px”][vc_column_text]

[/vc_column_text][vc_empty_space height=”20px”][vc_separator type=”normal”][vc_empty_space height=”20px”][vc_column_text]

Summary of object-oriented programming in Java

The image illustrates some of the elements of object-oriented programming that we have looked at in this chapter. For more info have a look at the oracle website . But for now, let’s have a recap of the parts we have looked at.[/vc_column_text][vc_empty_space height=”30px”][vc_single_image image=”20061″ img_size=”large” alignment=”center” onclick=”link_image” qode_css_animation=””][vc_empty_space height=”60px”][vc_row_inner row_type=”row” type=”full_width” text_align=”left” css_animation=””][vc_column_inner width=”1/3″][vc_single_image image=”20063″ img_size=”large” alignment=”center” onclick=”link_image” qode_css_animation=””][/vc_column_inner][vc_column_inner width=”2/3″][vc_column_text]A class in Java describes the properties and attributes an object should have. The class acts as a template that describes how something is (attributes) and what it does (properties).

 

By creating multiple classes, you can create small models across the entire program that together create an entire program. Moreover, each class manages “its part” of the program and is completely independent of what other classes do, creating object-oriented programming.[/vc_column_text][/vc_column_inner][/vc_row_inner][vc_empty_space height=”70px”][vc_row_inner row_type=”row” type=”full_width” text_align=”left” css_animation=””][vc_column_inner width=”1/3″][vc_single_image image=”20064″ img_size=”large” alignment=”center” onclick=”link_image” qode_css_animation=””][/vc_column_inner][vc_column_inner width=”2/3″][vc_column_text]An object is an instance of a class that contains the information that the class specifies that the object must-have. That is the attributes (states) and the properties (methods). Often you create several objects from the same class. The objects are then entirely independent of each other, even though they come from the same class!

 

Often called encapsulation, which means that the object is entirely independent of other objects or code. Because the object only performs what it is instructed to do. Therefore, a programmer only needs to know how to communicate with the object, without knowing how the object performs the task.[/vc_column_text][/vc_column_inner][/vc_row_inner][vc_empty_space height=”30px”][vc_column_text]

[/vc_column_text][vc_empty_space height=”40px”][vc_row_inner row_type=”row” type=”full_width” text_align=”left” css_animation=””][vc_column_inner width=”1/3″][vc_single_image image=”20065″ img_size=”large” alignment=”center” onclick=”link_image” qode_css_animation=””][/vc_column_inner][vc_column_inner width=”2/3″][vc_column_text]We use Inheritance in Java to reuse code from other classes. Many times you want to reuse code from classes you have already programmed. Instead of coding similar classes several times, it’s possible to inherit code from another class. A class that inherits code is called a subclass, and its parent is a superclass[/vc_column_text][/vc_column_inner][/vc_row_inner][vc_empty_space height=”70px”][vc_row_inner row_type=”row” type=”full_width” text_align=”left” css_animation=””][vc_column_inner width=”1/3″][vc_single_image image=”20066″ img_size=”large” alignment=”center” onclick=”link_image” qode_css_animation=””][/vc_column_inner][vc_column_inner width=”2/3″][vc_column_text]An interface determines what methods a class should have; this is very effective when we want to create several classes with similar properties. In larger projects, you may be several separate project groups that are coding for the same project. Then it is highly important to have predetermined requirements so that all programmers based on the same provision.[/vc_column_text][/vc_column_inner][/vc_row_inner][vc_empty_space height=”70px”][/vc_column][/vc_row][vc_row css_animation=”” row_type=”row” use_row_as_full_screen_section=”no” type=”full_width” angled_section=”no” text_align=”left” background_image_as_pattern=”without_pattern”][vc_column][vc_column_text]

Previous Page    |    Next Page

[/vc_column_text][vc_empty_space][/vc_column][/vc_row]