What is the maximum possible length of the variable name according to The Java Language Specification?
Explanation
There is no limit to variable name size in the Java Language Specification. However, there is an implicit implementation limit in the class file format (The Java Virtual Machine Specification):
The length of field and method names, field and method descriptors, and other constant string values (including those referenced by ConstantValue (§4.7.2) attributes) is limited to 65535 characters by the 16-bit unsigned length item of the CONSTANT_Utf8_info structure (§4.4.7).

BarsaX, you are right. Question and explanation are updated now.

2017 May 12, 10:26:47 PM

It is not unlimited and actually 65535 characters. 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.

2017 Feb 24, 2:35:05 PM

Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback