Possible Duplicate:
Max name length of variable or method in Java
I was reading the java docs and it says “A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits … “ in c++ the variable name length is around 255 characters depending on the compiler, so how is this handled in java does the compiler truncate the variable name after x number of characters, and if this is true what would be x ?
There is no limit on the length of the variable name. A variable name cannot contain spaces.
ANSI standard recognizes a length of 31 characters for a variable name. However, the length should not be normally more than any combination of eight alphabets, digits, and underscores.
An identifier should be of length 4-15 letters only. However, there is no limit on its length. But, it is good to follow the standard conventions. We can't use the Java reserved keywords as an identifier such as int, float, double, char, etc.
Variable names are up to 64 characters long and can only contain letters, digits and nonpunctuation characters (except that a period (.) is allowed.
According to the class file format spec (under section 4.11):
The length of field and method names, field and method descriptors, and other constant string values is limited to 65535 characters by the 16-bit unsigned length item of the CONSTANT_Utf8_info structure (§4.4.7). Note that the limit is on the number of bytes in the encoding and not on the number of encoded characters. UTF-8 encodes some characters using two or three bytes. Thus, strings incorporating multibyte characters are further constrained.
This applies to local variables as well because of the LocalVariableTable pointing to CONSTANT_Utf8_info values for the variable names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With