aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is the length limit of String literal? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "what is the length limit of String literal?" Watch "what is the length limit of String literal?" New topic
Author

what is the length limit of String literal?

Guoqiao Sun
Ranch Hand

Joined: Jul 18, 2001
Posts: 317
Hi, all, if I define a String like this:

Is there any lengh limitation for the String str? In other word, can I define a very very long String using this method?
Thanks in advance!
------------------
Guoqiao Sun
Sun Certified Programmer for Java™ 2 Platform
try my mock exam¹²³ at my homepage.


Guoqiao Sun<br />SCJP2 SCWCD2<br />Creator of <a href="http://www.jiris.com/" target="_blank" rel="nofollow">www.jiris.com</a>, Java resource, mock exam, forum
ashok khetan
Ranch Hand

Joined: Jul 29, 2001
Posts: 153
hi sun!
i think u can, as much as u like!!
ashok.
Guoqiao Sun
Ranch Hand

Joined: Jul 18, 2001
Posts: 317
Thank you, ashok!
By the way, I have added your words into my first mock exam which you emailed to me last week.
Best regards,
Originally posted by ashok khetan:
hi sun!
i think u can, as much as u like!!
ashok.


------------------
Guoqiao Sun
Sun Certified Programmer for Java™ 2 Platform
try my mock exam¹²³ at my homepage.
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

Guoqiao,
I read an old post on it a few months earlier (i can't remeber where )....and the folks concluded that Strings have no limits in size and only JRE considerations will act as a limitation (like ur RAM/virutal memory shortage causing a large heap to maintain)....etc....but i m not sure anyway!
But in sense it tells that a java object can contain a lot info virtually without any limitation...so a string object is a java object...
------------------
Muhammad Ashikuzzaman (Fahim)
Sun Certified Programmer for the Java� 2 Platform
--When you learn something, learn it by heart!


Ashik Uzzaman
Senior Member of Technical Staff, Salesforce.com, San Francisco, CA, USA.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
In the class file tha table CONSTANT_Utf8_info represents the information of the String literals, and several kinds of names: types, members, descriptors and attributes.
Given that the format of a CONSTANT_Utf8_info table has only two unsinged bytes for the length of the bytes representing the information of a String literal, I think the maximum size of a String literal, written as code, is 16536.
Yes, a String literal could be made to grow more than that via a for sentence, but doing so would not spawn an entry in the class file that exceedes the limit of the CONSTANT_Utf8_info table.


SCJP2. Please Indent your code using UBB Code
 
I agree. Here's the link: http://jrebel.com/download
 
subject: what is the length limit of String literal?
 
Similar Threads
java.lang.StringIndexOutOfBoundsException: String index out of range: -2
how can we make class "immuatble" explicitly
importing package in jsp
class in interface!
The reference to entity "G" must end with the ';' delimiter