Structured Programming   «Prev  Next»
Lesson 7 Object-oriented programming terminology
ObjectiveUnderstand basic object-oriented programming terminology.

OO Programming Terminology

Computer programs that perform complicated tasks tend to be very large, and as you might imagine, large programs tend to be hard to create and to maintain. Over the years a number of different programming models have evolved to address this issue. At the core of each of these models is the strategy of solving large, complex problems by partitioning them into smaller, simpler problems. Most programming languages are designed to primarily support a single programming model. Java is an object-oriented programming language. Although this course will not be focusing on Java's object-oriented programming features, it is necessary for you to have a basic understanding of several object-oriented programming concepts and terms.
In Java, a program is made up of one or more classes. Very roughly speaking, a class is a collection of data along with instructions for what to do with the data. The data in a class is stored in variables, and the instructions in a class are implemented as methods (similar to functions or procedures in procedural languages such as C or BASIC). Variables and methods can be associated with a class or with instances of a class called objects.
If these terms seem a bit confusing at this point, that is to be expected. As you proceed through the course, your understanding of these concepts will deepen. The primary reason for introducing this terminology now is that all Java programs, even very simple Java programs, consist of classes, variables, and methods.

Object-Oriented Basics

Objects are the fundamental building blocks of Java programs. Each object belongs to a class, which defines the object’s capabilities in terms of its public variables and methods. This section introduces some object-oriented concepts and terminology necessary for the rest of the chapter.

APIs and Dependencies

The public variables and methods of a class are called its Application Program Interface (or API). The designer of a class is expected to document the meaning of each item in its API. Java has the Javadoc tool specifically for this purpose. The Java 9 class library has an extensive collection of Javadoc pages, available at the URL docs/api. If you want to learn how a class from the Java library works then this is the first place to look. Suppose the code for a class X holds an object of class Y and uses it to call one of Y’s methods. Then X is called a client of Y. Listing 5-7 shows a simple example, in which StringClient is a client of String.

Listing 5-7: The StringClient Class
public class StringClient {
 public static void main(String[] args) {
  String s = "abc";

In the next lesson we will take a closer look at the HelloWorld program.