Logout

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 as "canned" IB exam prepared answers is simple definitions as follows, but look below for more details, as covered in the "old school" white board lecture. Note that with the 2015 video of that, the sound was unfortunately not captured. :-( But come to think of it, that's just as well for this assessment statement, since you are dealing with written communication here; you need to be able to define these in words, and conversely understand what is being described by these words. (Though adding a quick little diagram never hurt a definition kind of exam answer.)


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).

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.