in documentation i read, that:
A variables name can be any legal identifier — an **unlimited-length** sequence of Unicode letters and digits
so
The compiler has probably changed your really long name to something boring like "a".
The variable name is there for the programmer's convenience. To the compiler and JVM it makes no difference if it's 1 character or 1 million as long as it's unique.
The local variable names are not stored as such. They tend to be removed as part of the compiler optimization and replaced with numbers (see aload_<n> for example).
Try to compile with javac -g
or javac -g:vars
, it should leave more information, which you'll be able to check with javap
.
This answer should have interesting details on this topic.
Since your example code doesn't actually do anything anyway, it's likely to be optimized into an empty method.
1) I wouldn't be surprised if some compiler implementations had (reasonable) limits while others could handle variable names of any length. Unfortunately, I don't know of any documented specific examples or have any specific experiences of either off-hand.
2) Local variables names don't have to be maintained in the class file (they aren't accessible via reflection). Try making a file with an instance variable name that long and see the resulting class file.
iiiiiii..
is a local variable, i.e. it cannot be accessed from other classes. Therefore, its name does not matter; the compiler does not need to store it. Additionally, the compiler may look at your code and determine that {int i = 10;}
is not actually doing anything and can be replaced by {}
since both versions produce the same program output (none).