The Many Different Kinds Of Programming Languages English Language Essay

Published: Last Edited:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

With object-oriented programming languages developers work from the data and build functionality to apply to the data, as opposed to procedural programming that works from the procedures. In object-oriented programming applications are created by building objects that contain both data and methods to manipulate that data. Methods provide the functionality needed to use the data and consist of a method signature (name, return type, and parameters) and a method body (how the method is implemented). By encapsulating the data and the methods needed to manipulate that data into objects programmers can greatly increase security over procedural programming.

The key advantage of using object-oriented programming is gained from the use of objects. With an object-oriented language developers get the advantage of having reusable code as well as the additional security provided by the structure of object-oriented programs. The data is encapsulated in the objects and can be further protected by making the data private, making it so the only way to access the data is through approved methods. Having a program made up of objects also makes debugging code easier. One of the most popular object-oriented languages available today is Java.

The execution of a Java application is performed via objects. Objects in Java are similar in concept to physical objects in that they both consist of states (fields) and behaviors (methods). Objects are constructed from classes. A main class often referred to as the driver is run when the application is executed and all the objects that make up the application are created and used from the driver. Java application development takes advantage of a group of techniques commonly referred to as APIE. APIE is an acronym for Abstraction, Polymorphism, Inheritance, and Encapsulation, which are the four concepts that make up the core of object-oriented programming and Java. The techniques that make up APIE deal directly with the creation and operation of classes and the objects created from them.

Encapsulation is a technique that restricts accessibility to private fields (data) by requiring the use of public methods and is an important security feature of the Java language. In Java, you can make a field private by using the private modifier, thereby requiring all interactions with the field be done through the class' methods. With this setup the Java programmer can ensure that the data can only be accessed or mutated in ways that they have designed and tested. The programmer-designed methods are encapsulated with the data into an object. The following code is an example of encapsulation:

public class EncapsulationExample {

private int protected = 20; // the protected data

public int changeProtected() { // the method to change the protected data

protected = 10;


In Java, classes can inherit fields, nested classes, and methods from other classes through a process called inheritance. Every class inherits from another class, which is called the superclass. The inheriting class is called the subclass. If no class is specified, then the class inherits from the Object class. A class is always a subclass of another superclass or class Object, and a class can only be a direct subclass of one superclass. All inheritance paths lead back to Object. Object is the only class that does not inherit from another class, as it is the top superclass. The fact that there is a single class that is always at the top of the inheritance chain, together with the rule that a class can only have one direct superclass, means that a class hierarchy is always in place.

One way to inherit from multiple locations without breaking the one superclass rule is to implement interfaces, which can provide additional method signatures, constants, and nested types for the class to use without breaking the one superclass rule. Interfaces do not include the body of its methods, just the signature. The contents of the method body are determined by the class that implements the interface. The methods in an interface are also called abstract methods. There is no limit to how many interfaces a class can implement.

To inherit from a class, the keyword extends must be used in the class declaration. To implement an interface, the keyword implements must be using in the class declaration. A class can inherit both from a superclass and implement interface. An example of a class declaration that both inherits and implements is:

public class Subclass extends Superclass implements Interface {

code snipped….


When looking at inheritance, the keyword final is used on methods in a class to ensure that that method cannot be overridden by a subclass. The keyword final can also be used for declaring a class final, in which case the class is prevented from ever being inherited by another class. The ability to declare a class or method final is an important feature to enhance the stability of an application. Declaring a method final can be beneficial when changing a method from its original implementation could have a serious negative impact on the state of an object, or if there is one and only one way a method can successfully be implemented. A class may be declared final if it is going to be an immutable class and should thus not be inherited.

Abstraction refers to the fact that Java allows for the creation of abstract classes. Abstract classes are used to define generic fields and methods that can be inherited and used by other classes. The inheriting class can then add more specific functionality thru techniques including polymorphism. Abstract classes exist only to be inherited by a subclass and can't be constructed into an object themselves. An abstract class' contents are so generic that an object created just from the contents of the abstract class would not be usable. It is only when the contents are inherited by a subclass and added to and otherwise expanded that the abstract class can become something usable. A huge advantage of abstraction is that an abstract class can contain code that can be inherited by many subclasses, greatly decreasing the amount of code needed in a program and decreasing development and debugging time. Abstraction also refers to the use of abstract methods, which are methods that are incomplete and are completed by the classes that inherit them. Abstract classes only contain a method signature and do not contain method bodies. Abstract classes and methods are created by using the abstract keyword when the classes and methods are declared. An example of an abstract class that contains an abstract method is:

public abstract class GenericInfo { // abstract class declaration

String name; // field

Int id; // field

abstract void printInfo(); // abstract method declaration

In the example above, the abstract class is very generic. The fields and methods could be used in any number of situations. This class could easily be inherited by a class that deals with anything from medical records to a class that creates an employment roster. The abstract method lacks a body and needs to be completed by the class that inherits it. Abstraction's ability to re-use generic code in a more specific way is an important part of why object-oriented programming and Java are as powerful as they are.

Polymorphism is the ability of methods within an object to have the same name but take on many different forms and can occur either statically (at compile-time) or dynamically (at run-time). Polymorphism is used to allow a method that has been inherited to be altered to provide additional functionality or to allow a single method name to be used for several different methods within the same object. The Java Virtual Machine is designed to handle both of these types of situations. Abstraction is possible due to Java's ability to perform polymorphism. Polymorphism is important for when an inherited method is too generic to be used as-is and requires alterations to make it more specific and useful to the object that inherited it, as well as when methods need to perform the same action but with different variables.

Static polymorphism is when at compile-time the Java compiler can determine which version of any number of identically-named methods will be used when the method is called in the program. An example of static polymorphism is method overloading. Method overloading is when multiple methods are in the same class, have the same name, but contain a different number/type of arguments. All the methods have the same level of precedence and which method should be used for a call is determined at compile-time based on the arguments used in the method call. Static polymorphism is useful for cases where a single method could be used with several different types of data. Instead of creating methods with different names for each case, a single method name can be used for each method, as long as each method passes in a different type/amount of arguments. Though this can make reading the code a little more difficult, it can greatly reduce the number of different method names that have to be kept track of. An example of method overloading is:

public class OverloadExample {

private int i = 1;

private String s = "string";

public void print( int i) { // first copy of method print

// method body goes here


public void print(String s) { // second copy of method print overloads the first copy

// method body goes here



Dynamic polymorphism is when the compiler cannot tell which version of a method should be used for a method call and that information has to be determined at run-time. Dynamic polymorphism is also referred to as method overriding. Method overriding, as opposed to overloading, is when instance methods have the same name, the same type/number of arguments, and the same return type, but are in different classes. Also, in method overriding the original method is replaced within the subclass, as opposed to overloading where each overload is treated as another new method. Method overriding happens when an instance method is inherited from a superclass and then added to, perhaps to include new fields that were created by the subclass. At run-time, the modified method in the subclass can "override" the originally inherited method. Dynamic polymorphism is important in situations where the method that a subclass inherits from a superclass does not do everything that it needs to, but does enough to still be usable with a few additions. This can greatly reduce the amount of code that needs to be written for an application. The following is an example of method overriding:

public class Superclass { // superclass

private int iOne = 1;

private int iTwo = 2;

private int total;

public void getTotal { // original getTotal

total = intOne + intTwo;



public class Subclass extends Superclass { // subclass inherits all fields and methods from Superclass

private int iThree = 3; // field only in subclass

public void getTotal { // overridden getTotal

total = intOne + intTwo + intThree; // overrides the body in the inherited getTotal



In addition to static and dynamic polymorphism, upcasting and downcasting are both important concepts that relate to polymorphism. In Java, objects can be changed to be of a different class than the one it was originally constructed from. This is done through techniques called upcasting and downcasting. Upcasting is when an object is changed to be of a class higher up in the inheritance hierarchy than its current class. Downcasting is when an object is changed to be of a class lower in the inheritance hierarchy. In both cases, the visibility of the object changes to that of the class it has been upcasted or downcasted to. If a called method has been overridden at all levels of the hierarchy, an upcasted or downcasted object will use the version of that method that is from the class that the object was originally constructed from. This kind of behavior is an act of polymorphism.

There are several advantages that are gained by using the techniques that make up APIE. The ability to reuse code by using inheritance, abstraction, and polymorphism is useful not only for reducing development time, but also helps in making code consistent and reduces the amount of bugs that may be found in the code, increasing an application's stability. Code also becomes more versatile, especially when polymorphism is used. Using the APIE techniques also provides security to your data through the use of encapsulation by giving the Java developer complete control over how the data in the application is used. The powerful techniques of abstraction, polymorphism, inheritance, and encapsulation are essential to Java programming and the strengths they add to applications built with Java are a key reason for Java's popularity and wide use by programmers around the world.


(2010) The Java Tutorials, October 18, 2010, retrieved on October 30, 2010 from (