What is the String constant pool in Java, and what exactly gets interned into it?
The String constant pool is a special area of memory that the JVM uses to store String literals and the results of intern(). Its defining rule is that every distinct literal value has exactly one canonical instance, and the pool hands out references to that instance. Two pieces of code that both write "hello" therefore end up pointing at the same object.
Three kinds of value end up in the pool. String literals written directly in the source. The compiled constant pool of each class file, which the class loader resolves at link time, is where the literal comes from. And the results of calling intern() explicitly.
What is not in the pool is any String built at run time by concatenation of non-constant expressions, or by new String(...), or by reading from a file. Those are ordinary heap objects like any other. The exception is the compile-time constant folding: if every operand of a + is a compile-time constant, the compiler folds the expression into a single literal, and that literal is interned like any other.
Because interning means one instance per value, the pool also acts as a garbage-collection root for those entries. The pool used to live in the permanent generation, which was never collected; it now lives on the heap, so pooled Strings can be reclaimed under memory pressure. That change is invisible in normal code and important under load, and it is why old advice about permanent generation size no longer applies.
The practical reason the pool matters is performance: a literal comparison against a pooled String can be a cheap reference check, and the shared instances cut memory use for repeated values.