Streams: Yes. Java doesn't have destructors, so objects can't take care of their own cleanup. Some amount of cleanup is done at garbage collection time (finalizers), but it's not good programming practice to rely on that.
One of the reason "finally" blocks exist in Java is to take care of resource deallocation.
Memory allocation: looks like it does't. I created the following program:
public class deleteme
{
public static void main( String[] args )
{
int a;
String s;
}
}
Compiled it, then decompiled using javap -c, and got:
public class deleteme {
public deleteme();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: return
}
Looks like nothing really happens, except for initializing my main class.
Then i changed the code to say:
int a = 1;
String s = "";
compiled, decompiled and got:
public class deleteme {
public deleteme();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: iconst_1
1: istore_1
2: ldc #2 // String
4: astore_2
5: return
}
You can clearly see the additional instructions in the "main" method, where the memory is allocated.
I have a feeling that different versions the Java compiler might handle this differently.