Logout

Home OOP Option Last Next

D.3 Program development (20 hours)


D.3.1

Define the terms: class, identifier, primitive, instance variable, parameter variable, local variable.

 

Teaching Note:

These are generally related to the object’s data. See JETS.

 

Sample Question:

sdfsdfsf

JSR Notes:

Really, all you need for these definitions here and on D.3.2 and D.3.3 is simple, "canned" IB definitions as immediately follows. But look below for more details as well, to help with your understanding.

And now would be a good time to metion that sometimes, for definition questions, that adding a quick little diagram often doesn't hurt if it's appropriate.


Definitions:

class - a discrete group of attributes and methods which work with each other.

identifier - the name of a variable. (A variable being a short-cut for a memory address.)

primitive - a data type with is literally the value which it represents (as opposed to an object, or "reference" type, which is an address pointing to the data). Like int, char, double.

instance variable - a variable identifier (i.e. a named short-cut) for the address at which an instance of a certain class is held in memory.

parameter variable - a variable that is received by a method, sent (as an "argument") from some other part of the program when that method was called.

local variable - a variable declared within a block of code. In Java it is "garbage collected" at the close brace of the block in which it was defined.

 

More Details:

class - a discrete group of attributes and methods which work with each other.
And we know, certainly, what classes are; several to many classes make up a project, and consequently a full program.

identifier - the name of a variable. (A variable being a short-cut for a memory address.)
Basically, the name of anything that we ourselves make is an identifier. You could even say that the class names we pick for our classes are identifiers, but usually you think of an identifier being a variable identifier. And along with the "variable identifiers" for primitives, like int and boolean, there are "instance variable identifiers" which we use as identifiers for instance objects of classes we make, like our br of BufferedReader, or any other such instance variable identifiers we make in lines which use the "new" keyword.

primitive - a data type with is literally the value which it represents (as opposed to an object, or "reference" type, which is an address pointing to the data).
The Java primitives we regularly use in IBCS are int, double, char, and boolean, though there are a few others IB doesn't require you to know, but we have looked at them: short, long, and float.
So if we declare a primitive variable, like

int x = 22;
then in memory, what x points to is literally the integer value 3.



instance variable - a variable identifier (i.e. a named short-cut) for the address at which an instance of a certain class is held in memory.
So every time there is a line using the "new" keyword, for example,

Marker m = new Marker(10, "black");
we have made an instance variable. In the example, the variable identifier is m. And that variable identifier points to a place in memory which is actually a memory address; the memory address where the object is stored.



parameter variable - a variable that is received by a method, sent (as an "argument") from some other part of the program when that method was called.
So any method which takes in information from where it was called, this information comes in in the form of parameter variables. Most methods, in fact, do take in parameter information. The most obvious example of this is a "set method", or as we are about to call them "mutator method". A header line for a set method, for example, would be:

 public void setLength(int length)
and "length" is the one parameter being taken in.




local variable - a variable declared within a block of code. In Java it is "garbage collected" at the close brace of the block in which it was defined.
We looked before at the "scope" of where a variable can be used, and it's simply that: that a variable can be used only within the block of code in which it was defined. Note that it is possible for a variable to have "global scope", i.e. scope within a whole class, by being declared inside the class block, not inside of any of the class' methods. This way the variable can be used anywhere in the class.