Is there a way to make classes as stack variables in Java, or am I too much in the C++ mindset?
<p>I am somewhat familiar to Java, but am using it more now for Android.</p>

<p>Anyway, I'm kind of wondering if the only way to instantiate a class variable in Java is to allocate it onto the heap.</p>

<p>For instance: </p>

<pre><code>[C++ Land]
Foo foo;
foo.doSomeAwesomeStuff(9001);

[Java Land]
Foo foo = new Foo();
foo.doSomeAwesomeStuff(9001);
</code></pre>

<p>This kind of irks me because there are some things in Java where I just want a temporary variable like a placeholder Matrix, but I don't want to waste the system's heap by throwing garbage onto it.</p>

<p>I feel like this might be a call for the android-ndk then, but that feels too much like overkill.</p>
