Java Array of Objects crashes
<p>Java noob question:</p>

<p>Consider the following C array and initializer code:</p>

<pre><code>struct {
  int x;
  int y;
} point_t;

point_t points[1000];
</code></pre>

<p>Easy.  This gets created and memory allocated at load time.</p>

<p>Now consider the similar in Java:</p>

<pre><code>public class point_t
{
   public int x;
   public int y;
}

point_t points[] = new point_t[1000];
// Without this loop, java will crash when you run this
for (int i=0; i&lt;1000; i++)
{
   points[i] = new point_t;
}
points[0].x = 10;  // Crash would occur here without above loop
points[1].x = 10;
</code></pre>

<p>Initially my java program was crashing with a null pointer dereference.  The problem was that, coming from C++, I was not aware that you have to create the 1000 point_t objects.  Just a comment but this seems INSANE.  Suppose the array size was 1 million or 1 billion.  It would literally take seconds simply to "create" this array with empty entries at run time.  In C++ it all happens at load time.  I admit that you don't always know what would be in the C++ array's cells, but in embedded systems where I work, quite often the memory is auto initialized to zeros so it works.</p>

<p>So is there any easier, quicker, more efficient way in Java to create an array and allocate the memory when you have an array of objects?  Or am I doing something wrong in the code above?</p>
