Java Reference
In-Depth Information
Example 3.3 Example two-dimensional array syntax
int [][] ragtag = new int[35][10];
for (int i=0; i<35; i++) {
for (int j=0; j<10; j++) {
ragtag[i][j] = i*j;
} // next j
} // next i
Multidimensional arrays are built as arrays of arrays. Therefore, we can
actually allocate it in a piecemeal fashion and have ragged-edged arrays, where
each row has a different number of columns, as shown in Example 3.4.
Example 3.4 Ragged two-dimensional array syntax
int [][] ragtag = new int[17][];
for (int i=0; i<17; i++) {
ragtag[i] = new int[10+i];
} // next i
for (int i=0; i<17; i++) {
System.out.println("ragtag["+i+"] is "+ragtag[i].length+" long.");
} // next i
For a fuller discussion of arrays, see Chapter 9 of Eckel or Chapter 6 of
Lewis&Loftus.
3.2.2
The real power in Java, or any object-oriented language, comes not from the
scalar types, cool operators, or powerful control statements it provides (see
below), but from its objects .
Object-oriented programming is a relatively recent innovation in software
design and development. Objects are meant to embody the real world in a more
natural way; they give us a way to describe, in our programs, the real-world
objects with which we deal. If you are programming a business application,
think of real-world business objects such as orders, customers, employees,
Object Types
Search WWH ::




Custom Search