Source Code For:
"Java through the Eyes of a C++ Programmer", Part 2
Vol. 2, Issue 2 P.20

 

Listing 1: Static Initializers in Java.
public class Matrix {
private static int identityMatrix[8][8] = new int[8][8];

static {
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
// initialize diagonal elements to 1
identityMatrix[i][j] = (i == j ? 1 : 0);
}

// ...
}