This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Maximum Length for a Variable Name. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Maximum Length for a Variable Name." Watch "Maximum Length for a Variable Name." New topic
Author

Maximum Length for a Variable Name.

Udegbunam Morah
Ranch Hand

Joined: Oct 13, 2002
Posts: 36
Please, can someone help me with the maximum possible length for a variable name.

Thanks for your patience and understanding.


Udegbunam Ikechukwu Morah<br />B.Sc.,SCJP, MCP, OCP, PMP<br />Manager, Business COnsulting Group<br />Deep Business Solutions Limited
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

No idea. Why don't you just keep typing and see if you hit any problems?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Nick Stevens
Greenhorn

Joined: Nov 13, 2004
Posts: 15
I don't think there is a limit for variable name length, but if you
make the variable names too long then your code will run slower :-)
FELIX ALE
Greenhorn

Joined: Apr 08, 2005
Posts: 2
Variable names can be upto 32 digits.
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
32 digits ???
Do you mean length of the variable is restricted to 32 . No even this works
private int abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz = 78;


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
the length of a variable name can be a 32 bit integer number. Which number is the maximum the compiler will allow is open to experimentation.
Anyone wanting to try a variable name of 65000 characters is hereby invited to try


42
Horatio Westock
Ranch Hand

Joined: Feb 23, 2005
Posts: 221
Originally posted by Jeroen Wenting:
Anyone wanting to try a variable name of 65000 characters is hereby invited to try


I'll take that challenge

65535 - A-OK!
65536 - Oh no! UTF8 representation for string "aaaaaaaaaaaaaaaaaaaa..." is too long for the constant pool
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Well, I tried an int. Got to 2097088 characters in the variable name before the compiler ran out of memory (I was doubling its length from 65535 each time so you may well be able to create a bigger one). I'm so glad I know that now...
[ April 08, 2005: Message edited by: Paul Sturrock ]
 
wood burning stoves
 
subject: Maximum Length for a Variable Name.
 
Similar Threads
Question on new version assignment
Length of URL in get method
maximum length of String = 32k ?
maximum length of a string?
Max length of select statement