Reference Types
and Primitive Types
Types that have direct machine representation (e.g. integers, floating point,
characters, and booleans) are so represented (rather than being defined by a class),
and belong to the category of primitive types
.
Thus there are two distinct categories: reference
types/values/variables and
primitive
types/values/variables.
operators
: +
, *
,
!
, &&
.
Arrays
Even though arrays, are not defined by a class definition, they are considered objects (and thus reference values).
There is an important consequence here:
String a[];declares an array of Strings reference variable, not an object (i.e., the array itself)-- that must be created (just like an object of a class).
Analogous to creating an object of a class, creating an array object involves the new
operator:
String a[] = new String[20]; // Creates an array of 20 String references and assign the ref to a
Note that in turn, this did not create 20 String objects, but rather 20 String references (which can then reference
20 String objects)
Working with Arrays
fields
-- for the moment, we'll restrict
ourselves to the length
field.
int [] arr = new int[1000]; ... // Decide we need more array space int [] temp = new int[2000]; ... Copy the 1000 elements from arr's array to temp's arr = temp;