Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 981097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:29:17+00:00 2026-05-16T04:29:17+00:00

Inspired by the comments on this question , I’m pretty sure that Java String

  • 0

Inspired by the comments on this question, I’m pretty sure that Java Strings are interned at runtime rather than compile time – surely just the fact that classes can be compiled at different times, but would still point to the same reference at runtime.

I can’t seem to find any evidence to back this up. Can anyone justify this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:29:18+00:00Added an answer on May 16, 2026 at 4:29 am

    The optimization happens (or at least can happen) in both places:

    • If two references to the same string constant appear in the same class, I’d expect the class file to only contain one constant pool entry. This isn’t strictly required in order to ensure that there’s only one String object created in the JVM, but it’s an obvious optimization to make. This isn’t actually interning as such – just constant optimization.
    • When classes are loaded, the string pool for the class is added to the intern pool. This is “real” interning.

    (I have a vague recollection that one of the bits of work for Java 7 around “small jar files” included a single string pool for the whole jar file… but I could be very wrong.)

    EDIT: Section 5.1 of the JVM spec, “The Runtime Constant Pool” goes into details of this:

    To derive a string literal, the Java
    virtual machine examines the sequence
    of characters given by the
    CONSTANT_String_info structure.

    • If the method String.intern has
      previously been called on an instance
      of class String containing a sequence
      of Unicode characters identical to
      that given by the CONSTANT_String_info
      structure, then the result of string
      literal derivation is a reference to
      that same instance of class String.

    • Otherwise, a new instance of class
      String is created containing the
      sequence of Unicode characters given
      by the CONSTANT_String_info structure;
      that class instance is the result of
      string literal derivation. Finally,
      the intern method of the new String
      instance is invoked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inspired by the discussion in this question . We have all been taught that
This is inspired by this question and the comments on one particular answer in
Somewhat inspired by this question about a graphical programming environment. I don't think that
Inspired by this question why do we need user defined classloader in java Does
Inspired by this question , I'd like to know whether there is any trick
Inspired by the encoding scheme of the answer to this question , I implemented
The following question is inspired by this blog entry at ajaxian.com and this comment
Inspired by this question I decided to test the rank() function, trying to see
Inspired by this question . Short version: Why can't the compiler figure out the
G'day, Inspired by a comment I made in my answer to this question on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.