SE450: Java: Identifiers [13/22] ![]() ![]() ![]() |
One of the major advantages of assembly language over machine language is the ability to refer to data memory using names, or identifiers.
Some important properties of identifiers:
References are sometimes referred to as boxed values.
Plain values are then called unboxed.
A declaration is a statement that, when executed
,
binds a name to a data-memory location.
The scope of a declaration is the text of the program in which the binding has effect.
Lifetime is a dynamic property. Scope is a static property.
Value/Reference is really part of the type, but it is worth discussing separately.
A variable of value type T (synonym:
unboxed type) stores a value of type T.
A variable of reference type T
(synonyms: pointer type, boxed, type) stores a pointer to a
value of type T.
In java, all base-type identifiers hold values; all object-type identifiers hold references.
int x = 0; // value type (unboxed) String s = "dog"; // reference type (boxed)
primitive types are
booleanbyte, short, int, longcharfloat, doubleJava has wrapper classes in the java.lang
package that wrap all the primitive types.
String in Java is not a primitive type, but a class. However
it behaves like a special class, allowing string concatination using primitive
operators.
In Java, objects are always boxed (ie, identified by reference).
In C++, objects of any class may be boxed or unboxed. For example:
string* sp = new string("dog"); // boxed (requires delete) string s = string("cat"); // unboxed (no delete needed)