What are the functions of constants provided in Java?
According to my own understanding, there are several functions: 1, which convert values without human language meaning into variable names that human beings can understand. For example, there are many constants in the Color class. If 1 means red, 2 means green and 3 means blue. . . You can't remember so many colors. If you use red, green and blue, it is obviously much easier to remember. 2. Unification and standardization. If a class can have different states and needs a "quantity" to tell it what state it is in, then it is undoubtedly the best to use its own parameters at this time, which limits the scope of selection on the one hand and does not need to tell the outside world what specific values are used here on the other. 3. Facilitate the expansion of classes in the future. For example, at first, the color class agreed that 1 means red and 2 means green. Later, it was found that it was more reasonable to use 0 to represent red and 1 to represent green (here, it was just an analogy), so it could not be changed to this reasonable practice, because many people already used 1 to represent red. If the JDK is changed, others will find the original red color after using the new version of the JDK. But if we use the constant RED= 1, we just need to change it to RED=0 now, because all the places are "red" except this place, and all the places have corresponding changes. This is my humble opinion, I hope it can help you solve your doubts.