title: How are static arrays stored in Java memory?
body: <p>So in a language like C, memory is separated into 5 different parts: OS Kernel, text segment, static memory, dynamic memory, and the stack. Something like this:</p>
  
  <p><img src="https://i.stack.imgur.com/IyXbF.gif" alt="Memory Layout"></p>
  
  <p>If we declared a static array in C, you had to specify it's size beforehand after that would be fixed forevermore. The program would allocate enough memory for the array and stick it in the static data segment as expected.</p>
  
  <p>However I noticed that in Java, you could do something like this:</p>
  
  <pre><code>public class Test {
          static int[] a = new int[1];
  
          public static void main( String[] args ) {
                  a = new int[2];
          }
  } 
  </code></pre>
  
  <p>and everything would work as you'd expect. My question is, why does this work in Java?</p>
  
  <p>EDIT: So the consensus is that an <code>int[]</code> in Java is acts more similarly to an <code>int*</code> in C. So as a follow up question, is there any way to allocate arrays in static memory in Java (if no, why not)? Wouldn't this provide quicker access to such arrays?
  EDIT2: ^ this is in a new question now: <a href="https://stackoverflow.com/questions/6655338/where-are-static-class-variables-stored-in-memory">Where are static class variables stored in memory?</a></p>