I have scoured the Internet and have not found satisfying answers to my question. In a localized instance, if I have the code:
public static void main (String args[])
{
int x;
System.out.println(x);
}
...it will not compile, because the Java compiler will warn me that x should be initialized. I understand that.
My question is, will Java actually set aside 4 bytes of memory for the integer x? And if so, does it wipe out that block of memory? Does it define it as NULL (I don't think so because NULL and an int are incompatible types)? Or does the memory address of int x still retain the value last stored in memory, or does x just simply have "no value?"
I know that the above works in C, and that in C, it would just print out whatever is in that memory block. I want to know how Java handles this.
===EDIT===
Okay, okay. For some reason, my basic knowledge of programming had entirely exited my mind, as when a program does not compile, the question of memory allocation is irrelevant, as pointed out by both of the members who posted the answers. (Cue facepalm)
So what if I had the code:
public static void main (String args[])
{
int x;
}
How is the integer x resolved in memory then?
xdeclaration outside the main (and make it static), it will compile and x will still be uninitialized. it should print 0.