This question came up in Spring class, which has some rather long class names. Is there a limit in the language for class name lengths?
4 Answers
The Java Language Specification states that identifiers are unlimited in length.
In practice though, the filesystem will limit the length of the resulting file name.

- 664
- 2
- 12
- 41

- 67,031
- 36
- 206
- 278
-
7The Java VM Specification states that any constant string is restricted to 65535 bytes: http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html#88659 – user85421 Nov 27 '09 at 22:15
-
1This is from the second edition ( same as Jon's answer ) . There is no such reference in the third edition. – Robert Munteanu Nov 29 '09 at 21:42
-
1current link is broken – Lambart Jan 19 '16 at 18:32
65535 characters I believe. From the Java virtual machine specification:
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.
here:
https://docs.oracle.com/javase/specs/jvms/se6/html/ClassFile.doc.html#88659

- 16,433
- 7
- 64
- 79

- 62,090
- 32
- 125
- 150
-
Do you have a such a reference for the third edition? I'm unable to find one. – Robert Munteanu Jun 24 '09 at 15:24
-
11
-
I couldn't find the correct part in the third edition of the JLS. can anybody provide any further information? – Jonathan Holloway Jun 24 '09 at 16:16
-
Its the last point of the VM Specification chapter 4.10: http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html#88659 – user85421 Nov 27 '09 at 22:10
-
For Java 8: https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.7 – Christopher Schultz Feb 07 '18 at 21:40
With JDK 1.5, the practical limit for class names on Windows XP with 255 -- longer names gave errors in the file system. This was the full name (directory+package+class).
I have not tried JDK 1.6 on Vista or windows 7, hopefully Sun fixed it to be the NTFS limit of 8000 or so.

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

- 2,370
- 6
- 33
- 41