Java OOP Special Vocabulary
Java Object Oriented Programming Core – Part 4
Forward: In this part of the series, I talk about Java OOP Special Vocabulary.
By: Chrysanthus Date Published: 3 Sep 2012
Introduction
Declaration
Consider the following statements:
int myInt;
int myInt = 45;
Both of these statements are declarations in Java. The first one is pure declaration. The second one is also declaration but can be called, initialization, because the variable, myInt is given is initial (first) value. The second statement can be broken down into pure declaration and first assignment as follows:
int myInt;
myInt = 45;
Here the first statement is declaration. The second statement is not really declaration. It is more of definition (see later). The second statement here is normally just referred to as an assignment statement. In this situation it is the first assignment of the variable. To change the value of the variable, just retype the same assignment statement below in your code with the new value.
Consider the following class description:
class Calculator
{
int num1;
int num2;
Calculator(int ident1, int ident2)
{//constructor method
num1 = ident1;
num2 = ident2;
}
int add()
{
int sum = num1 + num2;
return sum;
}
}
Now, in Java a class description is called a class declaration. So, the above is a declaration. In Java a method description is called a method declaration or a method definition. So, in the above code, you have two method declarations, which are the constructor method and the add() method. In other words, you have two method definitions in the code.
Members
An object has all the properties and methods of the class. Properties and methods of a class (or object) are called members. So, you can talk of a member property or a member method.
What I have been calling properties is typically called member variables. Many Java documents use the phrase "member variables" or "instance variables". Java is not the only OOP language out there, and the more common name for member variables or instance variables is properties. So, in this volume I will be using properties must of the times. This is also to avoid the ambiguity of the names "member variables", "instance variables" or any other name the Java documents might have been using.
Field
In Java, a field is a place in memory (of an object) where datum (whether primitive object or instantiated object) is kept. Now, in one of the most recent documents I came across in Java, the word, field was used for property. In this volume I will be using field when I mean a place where datum is kept in memory and I will be using property when I mean member variable or instance variable. This is another reason while I insist on the word, property and not field or member variable or instance variable.
Definition
Some languages today have their inspiration from C++. In C++, a declaration that actually allocates a fixed amount of memory, is referred to as a definition. A similar thing applies to Java. In simple terms, an initialization of a variable with a value, is a definition. A method description is a definition, because the code of the method occupies an amount of memory. Java is not as close to the hardware as C++. It is not easy to know whether a statement or construct in Java is actually occupying a definite amount of memory. So avoid using the words, definition and define. Use them only when necessary.
Variables
There are 3 kinds of variables in Java: Member Variables, Variables in a Method and Parameters in a Method Signature (parentheses). Member variables are class properties. You have seen variables in methods before. In a method body (block), a variable can be declared, initialized or assigned a value. In the parameter list of a method definition or method signature, you have zero or more declared variables. The variables in the parameter list receive argument values.
Instantiation
In Java, the phrase is “instantiate a class”, you do not instantiate an object. However, I will be using the phrase “instantiated object” to differentiate such objects from the primitive objects (primitive data types).
That is it for this part of the series. We stop here and continue in the next part.
Chrys