class Demo {
public static void main(String[] args) {
int a; // declaration statement
a = 5; // initialization statement/expression?
}
}
I've looked into it, and it seems to be both a statement AND an expression. Is this true? Is there any documentation on this?
A local variable declaration - with or without initialization - is a statement, as specified in section 14.4 of the JLS.
It's important to note that this is not an expression in the way that a simple assignment expression is - you can't use it as part of a larger statement (other than a block). For example:
int x;
System.out.println(x = 5); // Prints 5
System.out.println(int x = 10); // Invalid
See more on this question at Stackoverflow