What are the differences between the Heap memory and the String Constant Pool in Java?

JavaObject Oriented ProgrammingProgramming

Heap Memory

  • The heap memory is a run time data area from which the memory for all java class instances and arrays is allocated.
  • The heap is created when the JVM starts up and may increase or decrease in size while the application runs.
  • The size of the heap can be specified using –Xms VM option. The heap can be of fixed size or variable size depending on the garbage collection strategy. Maximum heap size can be set using –Xmx option.
  • By default, the maximum heap size is set to 64 MB. 

String Constant Pool

  • String uses a special memory location to reuse of String objects called String Constant Pool.
  • String objects created without the use of new keyword are stored in the String Constant Pool part of the heap.
  • One of the important characteristics of String constant pool is that it does not create the same String object if there is already String constant in the pool.
Published on 28-May-2019 14:04:34