[ACCEPTED]-Does Java have a limit on the class name length?-name-length

Accepted answer
Score: 51

The Java Language Specification states that identifiers are unlimited 3 in length.

In practice though, the filesystem 2 will limit the length of the resulting file 1 name.

Score: 33

65535 characters I believe. From the Java 11 virtual machine specification:

The length 10 of field and method names, field and method 9 descriptors, and other constant string 8 values is limited to 65535 characters by the 16-bit 7 unsigned length item of the CONSTANT_Utf8_info 6 structure (§4.4.7). Note that the limit 5 is on the number of bytes in the encoding 4 and not on the number of encoded characters. UTF-8 3 encodes some characters using two or three 2 bytes. Thus, strings incorporating multibyte 1 characters are further constrained.

here:

https://docs.oracle.com/javase/specs/jvms/se6/html/ClassFile.doc.html#88659

Score: 3

With JDK 1.5, the practical limit for class 6 names on Windows XP with 255 -- longer names 5 gave errors in the file system. This was 4 the full name (directory+package+class).

I 3 have not tried JDK 1.6 on Vista or windows 2 7, hopefully Sun fixed it to be the NTFS 1 limit of 8000 or so.

Score: 0

No. Java doesn't impose any limit on the 3 class name. But if you interfacing with 2 other systems (e.g. JNI) its better to be 1 on the safe side.

More Related questions