Constant pool differentiation and explanation

Directory:
java virtual machine summary

  1. Class file structure analysis
    1). The constant item structure in the class file constant pool
    2). A collection of commonly used attribute tables
  2. Class loading process
    1). Principle and implementation of class loader
  3. Virtual machine structure analysis
    1) .jdk 1.7 and 1.8 version of the method area structure changes
    2). Simple distinction between constant pool <<== Current position
  4. Object structure analysis
    1). Detailed explanation of compressed pointers
  5. gc garbage collection
  6. Object positioning method

There is a constant pool in the first class file, called the class file constant pool (see the class file analysis for unclear ,
explained in detail) The second jdk1.8 has a runtime constant pool in our metaspace (just store some of your Defined class constants, nothing to talk about)
Third, there is a string constant pool in our heap. Let’s
talk about the string constant pool
String s = "ok". It
will first check if there is such a string in your string constant pool. String (use equal method to judge), if some, assign the address to s directly, if not, create an object in your string constant pool

That is to say
String s1 = "ok"
String s2 = "ok"
is the same address
s1==s2 true

And String s = new String("ok")
Attention! ! ! It will first check whether there is this object in your string constant pool. If not, an object will be created in both your string constant pool and the heap. These two objects are different.

Guess you like

Origin blog.csdn.net/lioncatch/article/details/106056228