In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail the example analysis of the Java constant pool for you. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
There are several different constant pools in java. The following is an introduction to several constant pools in java, the most common of which is the string constant pool.
(1) class constant pool
In Java, class classes will be compiled to form a Java file; class files in addition to containing the class version, fields, methods, interfaces and other description information, there is also a constant pool of information, used to store the compiler generated a variety of literals and symbol references, each class file has a class constant pool.
The literal quantity includes: 1. Text string 2. The value of eight basic types is 3. Constants declared as final, etc.
Symbol references include: 1. Fully qualified names of classes and methods 2. The name of the field and descriptor 3. The name and descriptor of the method.
(2) running constant pool
The runtime pool exists in memory, that is, the version after the class constant pool is loaded into memory, and is part of the method area (the JDK1.8 runtime pool is in metaspace, which is also an implementation of the method area). The difference is that its literal amount can be added dynamically (intern () of the String class), and symbolic references can be resolved to direct references.
When JVM executes a class, it must go through loading, connecting and initializing, and the connection includes three stages: verification, preparation and parsing. When the class is loaded into memory, jvm stores the contents of the class constant pool into the runtime constant pool, which is private to each class: basic type wrapper classes (wrapper classes do not manage floating-point types, shaping only manages-128to127s) and string types (that is, String can be forced into the constant pool through the String.intern () method). In the parsing phase, the symbolic reference is replaced with a direct reference.
(3) constant pool of basic type packaging class
Most of the wrapper classes of the Java basic type implement constant pool technology. The four wrapper classes Byte,Short,Integer,Long create cached data of the corresponding type with a value of [- 128127] by default. Character creates cached data with a value in the range of [0127]. Boolean directly returns True or False. If it exceeds the corresponding range, a new object is created. The two floating-point wrapper classes, Float,Double, do not implement constant pooling technology.
Integer cache source code:
/ * this method will always cache values in the range-128 to 127 (including endpoints), and can cache other values outside this range. * / public static Integer valueOf (int I) {if (I > = IntegerCache.low & & I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.