Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: markspace Newsgroups: comp.lang.java.programmer Subject: Re: how actually string store in java machine Date: Wed, 26 Mar 2014 08:32:42 -0700 Organization: A noiseless patient Spider Lines: 29 Message-ID: References: <8f7d9272-4b25-44c9-8c31-93ea754be4cb@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 26 Mar 2014 15:32:47 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="9358cda03e1e0dfd3c4b757daa608707"; logging-data="1462"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+t1S+D/M11PABoaYR4fHwREwgdkJm0hcw=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 In-Reply-To: Cancel-Lock: sha1:2wrPxlKPRJhyzhuZln3So9XlUVw= Xref: csiph.com comp.lang.java.programmer:27875 On 3/25/2014 7:37 PM, Roedy Green wrote: > On Tue, 25 Mar 2014 20:31:50 +0100, Jan Burse > wrote, quoted or indirectly quoted someone who said : > >> >> http://stackoverflow.com/questions/16690815/shared-constant-pool > > I was under the impression all string constants lived in the same pool > along with the interned strings. That would imply a shared constant > pool since day 1. Have I had this wrong since Java 1.0? > Yes, I'm pretty sure you've been wrong if that's what you thought. Each class has its own pool of strings. If you have a class with a constant string: String a = "a"; String b = "a"; The constant "a" is only stored once, and a==b will be true. But that's only for a single class file. Outside of the class file, each string is unique and a different object. I don't think any implementations of the JVM called String.intern() for each constant string read in each class file. And certainly if you read a string from a file or the network, the VM does not call String.intern() for you. That would be silly.